Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: When calc is linked with and uses GNU readline then for any multi-line copy-and-paste, only the first line is executed #138

Closed
malfisya opened this issue Dec 24, 2023 · 36 comments
Assignees
Labels

Comments

@malfisya
Copy link

Describe the bug
After version 2.14.10, pasting text (like from the example in readme) to interactive shell of calc handled differently/incorrectly.

To Reproduce

  • Run calc version after 2.14.0.10
  • Copy paste this function
config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)
  • The formatting get messed up and function failed to be solved

Expected behavior
The formatting get perserved and function get executed correctly

Screen shots
version 2.14.0.10 - Last good version
last good version.webm
version 2.14.0.13 - First time bug spotted
first bug spotted.webm
version 2.15.0.4 - Latest version available
latest version.webm

Execution environment (please complete the following information):

  • OS: Linux
  • OS version: Linux dev-solus 6.6.8-268.current
  • OS distribution: Solus and ArchLinux (All updated)
  • Calc Version : explained above
  • Shell and shell version : bash 5.1.16

Other Comment
Happy to provide another information if needed. Cheers!

@malfisya malfisya added the bug label Dec 24, 2023
@malfisya malfisya changed the title Bug: Pasting text to interactive shell handles differently after version 2.14.0.10 Bug: Pasting text to interactive shell handled differently after version 2.14.0.10 Dec 24, 2023
@lcn2 lcn2 self-assigned this Dec 25, 2023
@lcn2
Copy link
Owner

lcn2 commented Dec 25, 2023

Hello @malfisya,

Not near a system on which we can test, that might have to wait a few days.

QUESTION:

You indicate that calc release v2.14.0.10 does not exhibit this problem for you, while calc release v2.14.0.13 does exhibit this problem for you.

What about calc release v2.14.0.12. Does that exhibit the problem you describe?

Also are you compiling these versions or just installing from the binary rpms?

@malfisya
Copy link
Author

malfisya commented Dec 25, 2023

Hello!

Not near a system on which we can test, that might have to wait a few days.

That's fine. Happy holidays.

What about calc release v2.14.0.12. Does that exhibit the problem you describe?

I haven't tried it. Isn't this file missing some critical file? I can't build this version. I will be trying it again by adding those files manually.

Also are you compiling these versions or just installing from the binary rpms?

I am compiling it myself from the tarball (calc-x.x.x.x.tar.bz2) via Solus build system called solbuild. But this behaviour(bug) is also found in Archlinux package.

@lcn2
Copy link
Owner

lcn2 commented Dec 26, 2023

I haven't tried it. Isn't this file missing some critical file? I can't build this version. I will be trying it again by adding those files manually

If we recall correctly, the missing file was version.h, which can easily copied from the next release and edited to be the correct version.

@lcn2
Copy link
Owner

lcn2 commented Dec 26, 2023

Hello @malfisya,

Instead of trying the above, and thinking "out loud from afar" (of the keyboard) ...

We suggest that you first from a clone of the calc repo in some directory that does NOT have a calc:

git clone https://github.com/lcn2/calc.git
cd calc
make clobber

Try calc v2.14.0.10:

git checkout 769ac51f8cb40a8c06bcb370660bf1c2407c4642
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Try calc v2.14.0.11:

git checkout e213cc50723bbb1d13ca7a5c6f07300ca212ff94
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Try calc v2.14.0.12 (a version that can be compiled):

git checkout 0f6efb29bba08d269371634c4237438d8782a4a3
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Try calc v2.14.0.13:

git checkout ffd4422870cf81c83c06dd555fbbe64adbce803a
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Try calc v2.15.0.4:

git checkout 1d37930d22d867bdf9a5be4bf16a40d0bd44d7ea
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Try the latest on the master branch (and get out of the "detached head" state):

git checkout master
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

We recommend you do those steps. Which versions exhibit the problem you describe and which work as you expect?

@malfisya
Copy link
Author

malfisya commented Dec 26, 2023

Sorry, what is git co command mean?
git: 'co' is not a git command. See 'git --help'.

Figured it out. it is git checkout right? I never make that bash alias. 😆

@lcn2
Copy link
Owner

lcn2 commented Dec 26, 2023

Sorry, what is git co command mean? git: 'co' is not a git command. See 'git --help'.

Figured it out. it is git checkout right? I never make that bash alias. 😆

Sorry (tm Canada 🇨🇦), the alias is was a habit from old SCCS and RCS days. 🤓

FYI, here the useful parts of the [alias] section of our ~/.gitconfig that would apply to a general audience:

~/.gitconfig

@malfisya
Copy link
Author

malfisya commented Dec 27, 2023

So here is my findings:

  • Testing with the steps you gave, result in ALL VERSIONS exhibit that bug. Which is weird because v2.14.0.10 and earlier (v2.14.0.2) works as expected when built from tarball. These are steps I did when building from tarball.
    • Download tarball
    • Extract it and go inside the folder
    • Open terminal inside that folder
    • Run make -j1
    • Run sudo make install
    • Run calc
  • I tested those steps in Solus GNOME (my daily driver), Solus Plasma (VM), Solus Budgie(VM), and Fedora 39 LXQt (VM) .
  • So in gnome-terminal , konsole, gnome-terminal and qterminal respectively.

Sidenote:

Try calc v2.12.0.12 (a version that can be compiled):

I believe this is a typo. It should be v2.14.0.12

Try calc v2.12.0.13:

This too v2.14.0.13

Cheers!

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

Sidenote:

Try calc v2.12.0.12 (a version that can be compiled):

I believe this is a typo. It should be v2.14.0.12

Try calc v2.12.0.13:

This too v2.14.0.13

Cheers!

Corrected typos (sorry (tm Canada 🇨🇦)).

UPDATE 0

All of our "away from a terminal" comments are being typed into a cellphone, making it harder to catch typos.

It might be a few more days, before we are back to a real computer.

In the meantime, if you don't mind, we have a proposed test for to to try: test the current master branch of calc without using the GNU history and GNU readline libraries, and see what the multi-line paste does.

See below.

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

We were briefly near a terminal and tested those versions mentioned in the corrected comment 1869760653 on RedHat Enterprise Linux 9, current Debian Linux, current macOS.

None of them was able to be process as you referenced in your "version 2.14.0.10 - Last good version" screenshot.

We did the checkout, make clobber, compile, run and paste test. We could not find a calc version nor platform that performed as the "version 2.14.0.10 - Last good version" screenshot.

UPDATE 0

We were only briefly near a terminal, just enough to perform the above tests.

It might be a few more days, before we are back to a real computer.

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

Just as an FYI, and not really intended as a "fix".

We noticed in one of your screenshots that after pasting, as noted in your bug report:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

You then attempts to edit it into a 1-line compound command. As a 1-line compound command, it should be written as:

config("mode", "fraction"),; (17/19)^23; print base(16),(19/17)^29; print log(79.3i)

Or something like that. The ;'s in that 1-liner are important.

Again, this is not "fix", just an FYI.

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

One possible explanation for what might be happening is that the readline / history libraries that calc can use are rejecting (by their design) the multiple line paste, or maybe ignoring the text beyond the first new line of the paste.

This might point to the behavior in the GNU history library and GNU readline library, and not calc code itself.

We offer this not as an excuse, but as a possible explanation as to that is going on.

We agree that it would be nice if calc were to work as your "version 2.14.0.10 - Last good version" screen 📺 movie.

At one point in calc's development history, the use of the GNU history library and GNU readline library became compiled and were linked in by default. We will try to find out the calc version for which this happened.

It might be possible if you were to compile the current calc WITHOUT using GNU history library and GNU readline library, that the multi-line paste might work as you want it to.

Give the current master branch code an edit to disable compiling and linking of the GNU history library and the GNU readline library. See if that works as you want.

The above is not necessary intended as a "fix", but rather as a diagnostic step.

@malfisya
Copy link
Author

We did the checkout, make clobber, compile, run and paste test. We could not find a calc version nor platform that performed as the "version 2.14.0.10 - Last good version" screenshot.

Yes, that's what happens to me too. But building v2.14.0.10 from tarball performed as in "version 2.14.0.10 - Last good version" screenshot. Whether i build It from git or tarball, it should have the same result right? Did you try compile it from tarball not git?

Another sidenote:
I think you edit the wrong thing. Please, if you are caught up in something, don't feel pressured to answer my question right away. Take care.

@malfisya
Copy link
Author

Just as an FYI, and not really intended as a "fix".

We noticed in one of your screenshots that after pasting, as noted in your bug report:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

You then attempts to edit it into a 1-line compound command. As a 1-line compound command, it should be written as:

config("mode", "fraction"),; (17/19)^23; print base(16),(19/17)^29; print log(79.3i)

Or something like that. The ;'s in that 1-liner are important.

Again, this is not "fix", just an FYI.

Yes, it expects semicolon. Thank you

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

We think to compile and link calc without GNU readline and without GNU history you would need:

USE_READLINE= -UUSE_READLINE
READLINE_LIB=
READLINE_EXTRAS= -lncurses
READLINE_INCLUDE=

Or perhaps even without ncurses:

USE_READLINE= -UUSE_READLINE
READLINE_LIB=
READLINE_EXTRAS=
READLINE_INCLUDE=

You could add such lines you own Makefile.local, or you could use a make command of:

make clobber
make all USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS= READLINE_INCLUDE=

And then run the calc you just compiled:

make run

Again, the above is intended as a diagnostic, not as a fix.

Let us know what happeds, @malfisya .. thanks 🙏

@malfisya
Copy link
Author

  • Downloaded the tarball
  • Extract it and open folder in terminal
  • Run make clobber
  • Run make all USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS= READLINE_INCLUDE=
  • Run make run

Those steps solves the copy-paste bug. It behaves as the "version 2.14.0.10 - Last good version" screenrecord. Your suspicion might be right about GNU readline. Run make all USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS="-lncurses" READLINE_INCLUDE= works too.

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

  • Downloaded the tarball

  • Extract it and open folder in terminal

  • Run make clobber

  • Run make all USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS= READLINE_INCLUDE=

  • Run make run

Those steps solves the copy-paste bug. It behaves as the "version 2.14.0.10 - Last good version" screenrecord. Your suspicion might be right about GNU readline. Run make all USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS="-lncurses" READLINE_INCLUDE= works too.

Hello @malfisya ,

Thanks for that excellent report. So the current release of calc, when you built it without GNU readline and GNU history does not exhibit the multi-line copy-and-paste problem you reported. Correct?

Perhaps the multi-line copy-and-paste problem you detected is:

  • it may be a problem with GNU readline / GNU history, OR
  • it may be a problem with what GNU readline / GNU history is sending / not sending to calc, OR
  • it may be a problem with how calc is using GNU libs, OR
  • it may be a problem with the window manager pasting text, OR
  • it may be a problem with how calc is being built, OR
  • it may be something else

UPDATE 0

What we do NOT understand is how your "version 2.14.0.10 - Last good version" screen movie shows the copy-and-paste working as you expected. However when we tried that on several different platforms, we saw the multi-line copy-and-paste problem when you did not. We do not understand why this is the case.

To help rule out that this issue related to how the source is obtained and compiled, please try the following:

If you, in a directory that does not contain calc, do this:

git clone https://github.com/lcn2/calc.git
cd calc
make clobber

followed by this for calc version 2.14.0.10:

git checkout 769ac51f8cb40a8c06bcb370660bf1c2407c4642
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

Then if you do this for the current master branch:

git checkout master
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

Then if you do this:

make clobber
make all CCWERR= USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS="-lncurses" READLINE_INCLUDE= 
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

We know the above seems like a repeat (there are two minor differences that should not matter). We just want to be doubly sure.

QUESTION: Under what OS and window manager are you doing the above tests?

@lcn2
Copy link
Owner

lcn2 commented Dec 27, 2023

Hello @malfisya,

So in most cases for recent versions, calc appears to do nothing when one does this multi-line copy-and-paste:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

other than calc issuing a new prompt. However we do not think calc is completely ignoring the multi-line copy-and-paste, but rather we think calc is only processing (or perhaps only being given by the GNU library) the first line of the multi-line copy-and-paste. So we have a series of new tests for you to try if you are willing.

Try this from the master branch:

make clobber
git checkout master
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now just copy-and-paste this one line:

config("mode"); base()

We predict calc will print:

	"real"
        10
;

QUESTION: What did calc print for you for the above test?

Now copy-and-paste the following multi-line text, which is slightly different from your original example:

config("mode", "fraction"), base(16),
(17/19)^23
print
base(2),
(19/17)^29
print
log(79.3i)

If the copy-and-paste does NOT work as expected, then calc will just print:

;

QUESTION: What did calc print for you for the above test?

However, calc may be processing the first line of a multi-line copy-and-paste, or the GNU library may only be giving the first line of a multi-line copy-and-paste for calc to process.

Now copy-and-paste this one line again:

config("mode"); base()

We predict calc will print:

	"hexadecimal"
	0x10
;

QUESTION: What did calc print for you for the above test?

Now exit calc and then restart calc:

; exit
$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now copy-and-paste this multi-line text, which has been formatted somewhat differently:

config("mode", "fraction"), base(16), (17/19)^23
print base(2), (19/17)^29
print log(79.3i)

We predict calc will print:

	0x4084c92f140b1d16fd16ae71/0x34117ab6978baa7c1b53d233b
;

QUESTION: What did calc print for you for the above test?

And again if you copy-and-paste this 1-line into calc:

config("mode"); base()

Then we predict calc will print:

	"hexadecimal"
	0x10
;

QUESTION: What did calc print for you for the above test?

Finally, exit calc and restart calc one more time:

; exit
$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

and paste this multi-line text:

2+2;
This line is a syntax error!;
So is this line.;
3+3;

Then we predict calc will just print:

	4
;

QUESTION: What did calc print for you for the above test?

Thanks for you help in testing this problem! We know we have asked you to do a lot of tests for us and we appreciate you taking the time to do that and report what happens.

@malfisya
Copy link
Author

Hello @malfisya ,

Thanks for that excellent report. So the current release of calc, when you built it without GNU readline and GNU history does not exhibit the multi-line copy-and-paste problem you reported. Correct?

Correct.

Perhaps the multi-line copy-and-paste problem you detected is:

* it may be a problem with GNU readline / GNU history, OR

* it may be a problem with what GNU readline / GNU history is sending / not sending to calc, OR

* it may be a problem with how calc is using GNU libs, OR

* it may be a problem with the window manager pasting text, OR

* it may be a problem with how calc is being built, OR

* it may be something else

UPDATE 0

What we do NOT understand is how your "version 2.14.0.10 - Last good version" screen movie shows the copy-and-paste working as you expected. However when we tried that on several different platforms, we saw the multi-line copy-and-paste problem when you did not. We do not understand why this is the case.

To help rule out that this issue related to how the source is obtained and compiled, please try the following:

If you, in a directory that does not contain calc, do this:

git clone https://github.com/lcn2/calc.git
cd calc
make clobber

followed by this for calc version 2.14.0.10:

git checkout 769ac51f8cb40a8c06bcb370660bf1c2407c4642
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

No, it doesn't work as I expected.

Then if you do this for the current master branch:

git checkout master
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

No, it doesn't work as I expected.

Then if you do this:

make clobber
make all CCWERR= USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS="-lncurses" READLINE_INCLUDE= 
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

Yes, it works as I expected.

We know the above seems like a repeat (there are two minor differences that should not matter). We just want to be doubly sure.

QUESTION: Under what OS and window manager are you doing the above tests?

Solus 4.5 GNOME 45.2

@malfisya
Copy link
Author

Hello @malfisya,

So in most cases for recent versions, calc appears to do nothing when one does this multi-line copy-and-paste:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

other than calc issuing a new prompt. However we do not think calc is completely ignoring the multi-line copy-and-paste, but rather we think calc is only processing (or perhaps only being given by the GNU library) the first line of the multi-line copy-and-paste. So we have a series of new tests for you to try if you are willing.

Try this from the master branch:

make clobber
git checkout master
make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now just copy-and-paste this one line:

config("mode"); base()

We predict calc will print:

	"real"
        10
;

QUESTION: What did calc print for you for the above test?

Exactly that

    "real"
	10

;

Now copy-and-paste the following multi-line text, which is slightly different from your original example:

config("mode", "fraction"), base(16),
(17/19)^23
print
base(2),
(19/17)^29
print
log(79.3i)

If the copy-and-paste does NOT work as expected, then calc will just print:

;

QUESTION: What did calc print for you for the above test?

Exactly that

;

However, calc may be processing the first line of a multi-line copy-and-paste, or the GNU library may only be giving the first line of a multi-line copy-and-paste for calc to process.

Now copy-and-paste this one line again:

config("mode"); base()

We predict calc will print:

	"hexadecimal"
	0x10
;

QUESTION: What did calc print for you for the above test?

Exactly that

 	"hexadecimal"
	0x10
;

Now exit calc and then restart calc:

; exit
$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now copy-and-paste this multi-line text, which has been formatted somewhat differently:

config("mode", "fraction"), base(16), (17/19)^23
print base(2), (19/17)^29
print log(79.3i)

We predict calc will print:

	0x4084c92f140b1d16fd16ae71/0x34117ab6978baa7c1b53d233b
;

QUESTION: What did calc print for you for the above test?

Exactly that

	0x4084c92f140b1d16fd16ae71/0x34117ab6978baa7c1b53d233b
;

And again if you copy-and-paste this 1-line into calc:

config("mode"); base()

Then we predict calc will print:

	"hexadecimal"
	0x10
;

QUESTION: What did calc print for you for the above test?

Exactly that

	"hexadecimal"
 	0x10
;

Finally, exit calc and restart calc one more time:

; exit
$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

and paste this multi-line text:

2+2;
This line is a syntax error!;
So is this line.;
3+3;

Then we predict calc will just print:

	4
;

QUESTION: What did calc print for you for the above test?

Exactly that

 	4
;

Thanks for you help in testing this problem! We know we have asked you to do a lot of tests for us and we appreciate you taking the time to do that and report what happens.

Hey, no problem. Thank you for taking your time to take a look at this.

@lcn2
Copy link
Owner

lcn2 commented Dec 28, 2023

If you, in a directory that does not contain calc, do this:

git clone https://github.com/lcn2/calc.git
cd calc
make clobber

followed by this for calc version 2.14.0.10:

git checkout 769ac51
make clobber all chk CCWERR=
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

QUESTION: Does your multi-line copy-and-paste example work for you as you expect?

No, it doesn't work as I expected.

Thank you and .. interesting!

So when you compile calc v2.14.0.10 from GitHub, that version of calc does not work as you expected when given a multi-line copy-and-paste.

We are puzzled, then, as you why your screenshot of "version 2.14.0.10 - Last good version" worked as your expected.

Assuming your distribution has the ldd(1) command ..

and assuming that you still have the executable for that "version 2.14.0.10 - Last good version" ...

what does the follow command, executed from the directory of that "version 2.14.0.10 - Last good version" print:

ldd ./calc

REQUEST: After you verify that the "version 2.14.0.10 - Last good version" of calc that works, as you expect, with the multi-line copy-and-paste, please give us the output of the above ldd command.

It is our guess that the calc you ran did NOT have GNU readline and/or GNU history linked into the binary for that "version 2.14.0.10 - Last good version". We expect that the ldd(1) command above will show that calc is NOT linked with GNU readline and/or GNU history.

@lcn2
Copy link
Owner

lcn2 commented Dec 28, 2023

Hello @malfisya,

So in most cases for recent versions, calc appears to do nothing when one does this multi-line copy-and-paste:

config("mode", "fraction"),

(17/19)^23

print

base(16),

(19/17)^29

print

log(79.3i)

other than calc issuing a new prompt. However we do not think calc is completely ignoring the multi-line copy-and-paste, but rather we think calc is only processing (or perhaps only being given by the GNU library) the first line of the multi-line copy-and-paste. So we have a series of new tests for you to try if you are willing.

Try this from the master branch:

make clobber

git checkout master

make clobber all chk CCWERR=

CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now just copy-and-paste this one line:

config("mode"); base()

We predict calc will print:

"real"
    10

;

QUESTION: What did calc print for you for the above test?

Exactly that


    "real"

	10



;

Now copy-and-paste the following multi-line text, which is slightly different from your original example:

config("mode", "fraction"), base(16),

(17/19)^23

print

base(2),

(19/17)^29

print

log(79.3i)

If the copy-and-paste does NOT work as expected, then calc will just print:

;

QUESTION: What did calc print for you for the above test?

Exactly that


;

However, calc may be processing the first line of a multi-line copy-and-paste, or the GNU library may only be giving the first line of a multi-line copy-and-paste for calc to process.

Now copy-and-paste this one line again:

config("mode"); base()

We predict calc will print:

"hexadecimal"
0x10

;

QUESTION: What did calc print for you for the above test?

Exactly that


 	"hexadecimal"

	0x10

;

Now exit calc and then restart calc:

; exit

$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

Now copy-and-paste this multi-line text, which has been formatted somewhat differently:

config("mode", "fraction"), base(16), (17/19)^23

print base(2), (19/17)^29

print log(79.3i)

We predict calc will print:

0x4084c92f140b1d16fd16ae71/0x34117ab6978baa7c1b53d233b

;

QUESTION: What did calc print for you for the above test?

Exactly that


	0x4084c92f140b1d16fd16ae71/0x34117ab6978baa7c1b53d233b

;

And again if you copy-and-paste this 1-line into calc:

config("mode"); base()

Then we predict calc will print:

"hexadecimal"
0x10

;

QUESTION: What did calc print for you for the above test?

Exactly that


	"hexadecimal"

 	0x10

;

Finally, exit calc and restart calc one more time:

; exit

$ CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

and paste this multi-line text:

2+2;

This line is a syntax error!;

So is this line.;

3+3;

Then we predict calc will just print:

4

;

QUESTION: What did calc print for you for the above test?

Exactly that


 	4

;

Thanks for you help in testing this problem! We know we have asked you to do a lot of tests for us and we appreciate you taking the time to do that and report what happens.

Hey, no problem. Thank you for taking your time to take a look at this.

Thank you, and well then !!! ...

It seems that when calc in compiled and linked with GNU readline and GNU history, that such a calc, when given a multi-line paste ONLY processes the up the 1st line and that anything after the first line of a multi-line copy-and-paste is either NOT given to calc by the GNU library OR calc ignores the input beyond the first line of the multi-line copy-and-paste.

Hummm .. interesting.

@malfisya
Copy link
Author

Thank you and .. interesting!

So when you compile calc v2.14.0.10 from GitHub, that version of calc does not work as you expected when given a multi-line copy-and-paste.

We are puzzled, then, as you why your screenshot of "version 2.14.0.10 - Last good version" worked as your expected.

Assuming your distribution has the ldd(1) command ..

and assuming that you still have the executable for that "version 2.14.0.10 - Last good version" ...

what does the follow command, executed from the directory of that "version 2.14.0.10 - Last good version" print:

ldd ./calc

REQUEST: After you verify that the "version 2.14.0.10 - Last good version" of calc that works, as you expect, with the multi-line copy-and-paste, please give us the output of the above ldd command.

It is our guess that the calc you ran did NOT have GNU readline and/or GNU history linked into the binary for that "version 2.14.0.10 - Last good version". We expect that the ldd(1) command above will show that calc is NOT linked with GNU readline and/or GNU history.

Version 2.14.0.10 (last good version)

 ~ $ ldd /usr/bin/calc
	linux-vdso.so.1 (0x00007ffc9aedb000)
	libcalc.so.2.14.0.10 => /usr/lib/libcalc.so.2.14.0.10 (0x00007fe2c6070000)
	libcustcalc.so.2.14.0.10 => /usr/lib/libcustcalc.so.2.14.0.10 (0x00007fe2c6067000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007fe2c5e69000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007fe2c61ae000)

Version 2.15.0.4 (latest version)

 ~ $ ldd /usr/bin/calc
	linux-vdso.so.1 (0x00007ffd099f5000)
	libcalc.so.2.15.0.4 => /usr/lib/libcalc.so.2.15.0.4 (0x00007f26f1b1a000)
	libcustcalc.so.2.15.0.4 => /usr/lib/libcustcalc.so.2.15.0.4 (0x00007f26f1b11000)
	libhistory.so.8 => /usr/lib/libhistory.so.8 (0x00007f26f1b04000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f26f1906000)
	libreadline.so.8 => /usr/lib/libreadline.so.8 (0x00007f26f18b2000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007f26f1c67000)
	libncursesw.so.6 => /usr/lib64/libncursesw.so.6 (0x00007f26f1841000)

Spot on.

@lcn2
Copy link
Owner

lcn2 commented Dec 28, 2023

Version 2.14.0.10 (last good version)

~ $ ldd /usr/bin/calc
linux-vdso.so.1 (0x00007ffc9aedb000)
libcalc.so.2.14.0.10 => /usr/lib/libcalc.so.2.14.0.10 (0x00007fe2c6070000)
libcustcalc.so.2.14.0.10 => /usr/lib/libcustcalc.so.2.14.0.10 (0x00007fe2c6067000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fe2c5e69000)
/usr/lib64/ld-linux-x86-64.so.2 (0x00007fe2c61ae000)
Version 2.15.0.4 (latest version)

~ $ ldd /usr/bin/calc
linux-vdso.so.1 (0x00007ffd099f5000)
libcalc.so.2.15.0.4 => /usr/lib/libcalc.so.2.15.0.4 (0x00007f26f1b1a000)
libcustcalc.so.2.15.0.4 => /usr/lib/libcustcalc.so.2.15.0.4 (0x00007f26f1b11000)
libhistory.so.8 => /usr/lib/libhistory.so.8 (0x00007f26f1b04000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f26f1906000)
libreadline.so.8 => /usr/lib/libreadline.so.8 (0x00007f26f18b2000)
/usr/lib64/ld-linux-x86-64.so.2 (0x00007f26f1c67000)
libncursesw.so.6 => /usr/lib64/libncursesw.so.6 (0x00007f26f1841000)

Spot on.

Thanks for the confirmation!

Allow us to recap:

The "version 2.14.0.10 - Last good version" screenshot showed a multi-line copy-and-paste that worked because that version of calc was not linked to the GNU readline / GNU history (nor ncurses).

The "version 2.14.0.13 - First time bug spotted" showed a multi-line copy-and-paste that did NOT work because calc was linked to the GNU readline / GNU history.

Sometime between version 2.14.0.10 and 2.14.0.13, problems with how calc used dynamic shared libraries were corrected. Calc started being linked by default to GNU readline and GNU history.

Any modern (in the last few years) calc version that compiled and linked calc using a make line of the form:

make ... all ... USE_READLINE="-UUSE_READLINE" READLINE_LIB= READLINE_EXTRAS= READLINE_INCLUDE=

prevented calc from being linked to GNU readline / GNU history (nor ncurses), and thus allowed a multi-line copy-and-paste to calc to NOT work as expected.

The same goes for any calc version that was obtained from the github repo via some "git checkout something", and then compiled and run as:

make clobber all chk CCWERR=  
CALCPATH=./cal LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. CALCHELP=./help CALCCUSTOMHELP=./custom ./calc -q

The multi-line copy-and-paste did NOT work as expected because those version of calc were linked with and using GNU readline / GNU history.

The bug

When calc is linked with and uses GNU readline / GNU history, then for any multi-line copy-and-paste, only the first line is executed by calc.

What needs to be fixed

When a multi-line copy-and-paste is given to a calc linked with and using GNU readline / GNU history, is the reason why the text beyond the first line is NOT executed by calc because:

A) Calc is ignoring or discarding the rest of the input buffer beyond the end of the first line, OR

B) GNU readline / GNU history is not delivering data beyond the end of the first line, OR

C) Something else

The answer will help determine where a fix to calc's multi-line copy-and-paste unexpected behavior is needed.

UPDATE 0

Our guess is that neither GNU history, nor ncurses is a factor: only GNU readline.

We have modified the bug title accordingly.

Any guesses as to what might be wrong?

We also wonder if other applications that use the GNU readline library have run into a similar multi-line copy-and-paste problem.

@lcn2 lcn2 changed the title Bug: Pasting text to interactive shell handled differently after version 2.14.0.10 Bug: When calc is linked with and uses GNU readline / GNU history, then for any multi-line copy-and-paste, only the first line is executed Dec 28, 2023
@lcn2 lcn2 changed the title Bug: When calc is linked with and uses GNU readline / GNU history, then for any multi-line copy-and-paste, only the first line is executed Bug: When calc is linked with and uses GNU readline then for any multi-line copy-and-paste, only the first line is executed Dec 28, 2023
@malfisya
Copy link
Author

No idea. I am not usually using any TUI apps, so not much info. But, I will tell you if i find one. Cheers!

@lcn2
Copy link
Owner

lcn2 commented Dec 30, 2023

We are thinking about this issue .. and reached out to someone else to ask for advice.

In the mean time if anyone else has some suggestions, please feel free to comment.

@gromit1811
Copy link

Greetings from the "someone else" above 😉

I'm not aware of anything special that would be required to make multi-line paste with readline work. But I can reproduce this issue with calc 2.15.0.1 and readline 8.2 on Debian Linux. Out of curiosity, I also tried an older version of calc (2.12.7.2) linked against an older version of readline (7.0) and guess what: That worked as expected.

I'll try to find out what exactly is causing this. Might take a few days though, until I can dedicate enough time to this.

@gromit1811
Copy link

Additional data point: Old calc 2.12.7.2 with new readline 8.2 shows the problem as well, so it's triggered by the new readline version.

@gromit1811
Copy link

This seems to be caused by readline now defaulting to bracketed paste mode: https://utcc.utoronto.ca/~cks/space/blog/unix/BashBracketedPasteChange

Disabling bracketed paste as described there makes multi-line paste in calc work again for me. But that workaround shouldn't be required - I'll see what needs to be done in calc to make this work out of the box again.

@lcn2
Copy link
Owner

lcn2 commented Dec 31, 2023

This seems to be caused by readline now defaulting to bracketed paste mode: https://utcc.utoronto.ca/~cks/space/blog/unix/BashBracketedPasteChange

Disabling bracketed paste as described there makes multi-line paste in calc work again for me. But that workaround shouldn't be required - I'll see what needs to be done in calc to make this work out of the box again.

Thanks @gromit1811, looking forward to what you might find.

@gromit1811
Copy link

OK, found out a bit more. Even though readline's API documentation explicitly says that readline() returns a single line of text without the trailing newline, when pasting several lines and bracketed paste is enabled (default since readline 8.1), readline() returns all those lines at once and without removing the newline.

Now, when calc's ttychar() calls hist_getline() (which in turn calls readline()), it handles the returned string character by character until it sees the first newline. As soon as newline is encountered, the rest of the buffer gets dropped. Usually, this is not a problem, because hist_getline() is not supposed to return more than one line, i.e. the newline is always the final character. With the odd-behaving readline(), we'll lose everything after the first pasted line.

It would be relatively easy to modify calc to handle multiple lines returned by readline() properly (either by using another buffer inside hist_getline() which remembers pending lines across invocations or by modifying ttychar() to not drop the rest of the buffer when it sees newline). But I'd first like to clarify with the readline maintainers whether the behavior we see is actually intended. If so, they at least have to fix their documentation to avoid surprises like this (and then calc needs to implement one of the two fixes described above). If not, this problem might vanish by itself as soon as readline gets fixed.

@lcn2
Copy link
Owner

lcn2 commented Jan 2, 2024

OK, found out a bit more. Even though readline's API documentation explicitly says that readline() returns a single line of text without the trailing newline, when pasting several lines and bracketed paste is enabled (default since readline 8.1), readline() returns all those lines at once and without removing the newline.

Now, when calc's ttychar() calls hist_getline() (which in turn calls readline()), it handles the returned string character by character until it sees the first newline. As soon as newline is encountered, the rest of the buffer gets dropped. Usually, this is not a problem, because hist_getline() is not supposed to return more than one line, i.e. the newline is always the final character. With the odd-behaving readline(), we'll lose everything after the first pasted line.

It would be relatively easy to modify calc to handle multiple lines returned by readline() properly (either by using another buffer inside hist_getline() which remembers pending lines across invocations or by modifying ttychar() to not drop the rest of the buffer when it sees newline). But I'd first like to clarify with the readline maintainers whether the behavior we see is actually intended. If so, they at least have to fix their documentation to avoid surprises like this (and then calc needs to implement one of the two fixes described above). If not, this problem might vanish by itself as soon as readline gets fixed.

Interesting and thanks for your efforts so far, @gromit1811 .. please keep us posted and thanks 🙏

gromit1811 pushed a commit to gromit1811/calc that referenced this issue Jan 5, 2024
Fix for lcn2#138

According to
https://lists.gnu.org/archive/html/bug-readline/2024-01/msg00000.html
it's OK for readline() to return multi-line strings and/or newlines in case
of bracketed paste (enabled by default since readline 8.1) and also in other
situations even though its documentation explicitly states the opposite. So
we need to handle this properly in calc instead of just using the first line
and dropping the rest: Split the string returned by readline() into lines
and return line by line with each invocation of hist_getline(), each
possbily adding a terminating newline.
@gromit1811
Copy link

Seems this is intentional in readline() and just very badly documented. So we need to handle this in calc and split multi-line strings returned by readline(). See #139

Discussion on readline mailing list: https://lists.gnu.org/archive/html/bug-readline/2024-01/msg00000.html

@lcn2
Copy link
Owner

lcn2 commented Jan 5, 2024

Thank you @gromit1811 for your research, for overcoming the readline() documentation deficiency 🙄, and for pull request #139! It is now part of the master branch.

We invite people to test the top of the master branch while we begin extensive testing.

@malfisya
Copy link
Author

malfisya commented Jan 8, 2024

I have tried the master branch today. Now, copy-paste is working as expected but behaves slightly different than "last good version.webm". In that version if I copy this:

config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

It will paste like this :

; config("mode", "fraction"),
; (17/19)^23
; print
; base(16),
; (19/17)^29
; print
; log(79.3i)

On master branch it will paste like this :

; config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)

Is that intended? Is that what bracketed paste mean? It behaves the same as when I paste command from anywhere to terminal shell (bash, fish). I think this is a fine change. Making it a uniform experience inside terminal/shell.

On another note , I noticed that when I copy some examples from README to master branch calc it displayed a different result from the one provided. Such as this :

; config("display", 70),
epsilon(1e-70),
sin(1)
   0x1381e728a561e5a0ea8df7aacb4b8cab5c411f28ba271443a2c89af07/0x172ebad6ddc73c86d67c5faa71c245689c10795024000000000000000

and this :

; config("mode", "fraction"),
(17/19)^23
print
base(16),
(19/17)^29
print
log(79.3i)
	19967568900859523802559065713/257829627945307727248226067259

	0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1

	0x6561fca0841af56ca43bd7c47ffb50682b178266a95ae598e0361dbed27/0x35613870446fac65821ecbc6932bc881e4aa39bec57dc801ceba56b99ce+0x1235203c206c24ae36b4a5f19cca9897111179488ef6258a159b3472005/0x1ab09c382237d632c10f65e34995e440f2551cdf62bee400e75d2b5cce7i

Is there a change in default settings ? Cheers!

Update 1:
Edited text in bold. Also you might notice, english isn't my first language not even the second one. It might not come across well in the text above but what I want to say that : Yes, this change is in good direction. Cheers! (I always added "cheers" in the end to help any unintended unpleasant wording I used. ✌️ )

@lcn2
Copy link
Owner

lcn2 commented Jan 8, 2024

At first glance of comment 1880373356, @malfisya, the change seems like a good direction.

We have left the 👀 marker on your comment, because we intend to give your comment a 2nd glance and perhaps even a 3rd glance.

If you look at the single line "model", where the copy-and-paste is treated in a input single line, one has to treat those newlines inside the copy-and-paste buffer as it's separator tokens. So in this case the copy-and-paste buffer would be equivalent to this single line command:

; config("mode", "fraction"), (17/19)^23 print base(16), (19/17)^29 print log(79.3i)

Such a calc line above is a "syntax error".

You are correct that the current master branch treats copy-and-paste buffer newlines as if they were a ";" characters:

; config("mode", "fraction"),
; (17/19)^23
; print
; base(16),
; (19/17)^29
; print
; log(79.3i)

Interactive input consists of text (w/o a newline) followed by a newline. Copy-and-paste of multiple lines is like one were you enter each line of text, one newline terminated line at a time. It is likely that we might need to document the behavior of the master branch, perhaps in the help unexpected page, if that is the model we want.

Is that ideal? Perhaps it could be argued that it is not ideal, but at least it is not the "unexpected behavior/bug" that it was before the pull request by @gromit1811, and the behavior is documentable.

Well that is our initial take on the situation.

Comments, of course, are welcome.

@lcn2
Copy link
Owner

lcn2 commented Feb 2, 2024

Thank you @malfisya for raising this issue.

Thank you @gromit1811 for your recommended fix.

See commit bb3b861 and
See calc 2.15.0.5 release.

@lcn2 lcn2 closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants