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

somehow ctrl-c fails if copy_or_interupts is set and breaking out of an infinite loop #4713

Closed
skewballfox opened this issue Feb 17, 2022 · 11 comments
Labels

Comments

@skewballfox
Copy link

somehow ctrl-c fails if breaking out of an infinite loop
I'm not sure on what is actually relevant so I'll just post the function that I was trying to escape from
I had actually ran this 1-2 times before this, I was trying to debug an issue binding to sockets in a udp client/server program. I'm not sure why it worked once or twice before printing output in (unintentionally) never ending loop, but something is causing it to fail.

inline void choose_random_port(boost::shared_ptr<ip::udp::socket> socket, ip::udp::endpoint negotiation_endpoint, boost::system::error_code err)
{
    srand(time(NULL)); // initialize random seed
    int r_port;
    ip::udp::endpoint endpoint;
    do {
        r_port = rand() % int(pow(2, 16)) + 1024;
        endpoint = ip::udp::endpoint(boost::asio::ip::address_v4::any(), r_port);
        char msg[4 + sizeof(char)];
        std::sprintf(msg, "%d", r_port);
        std::cout << "UWU\n\n";
        socket->send_to(boost::asio::buffer(msg, 4), negotiation_endpoint, 0, err);

        socket->bind({ boost::asio::ip::address_v4::any(), r_port }, err);

    } while (err);
    std::cout << "\nRandom port chosen: " << r_port << "\n\n";

}

To Reproduce
Steps to reproduce the behavior:

  1. compile the code that uses above function
  2. run the associated code
  3. after UWU is repeatedly printed, press ctrl-c
  4. See error

Screenshots
If applicable, add screenshots to help explain your problem.
image

image

Environment details

kitty 0.24.2 created by Kovid Goyal
Linux Dominion 5.16.7-200.fc35.x86_64 #1 SMP PREEMPT Sun Feb 6 19:53:54 UTC 2022 x86_64
S
Kernel 5.16.7-200.fc35.x86_64 on an x86_64 (/dev/tty)

Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib64/kitty
  extensions dir: /usr/lib64/kitty/kitty
  system shell: /usr/bin/bash
Loaded config files:
  /home/skewballfox/.config/kitty/kitty.conf

Config options different from defaults:
background_opacity 0.8
font_family        Fira Code
font_size          12.0
shell              fish
Added shortcuts:
	ctrl+c → copy_or_interrupt

Environment variable names seen by the kitty process:
	BASH_FUNC_which%%
	CURRENT_DESKTOP
	CVS_RSH
	DBUS_SESSION_BUS_ADDRESS
	DEBUGINFOD_URLS
	DISPLAY
	EDITOR
	GBM_BACKEND
	GOPATH
	GUESTFISH_INIT
	GUESTFISH_OUTPUT
	GUESTFISH_PS1
	GUESTFISH_RESTORE
	HISTCONTROL
	HISTSIZE
	HOME
	HOSTNAME
	I3SOCK
	INVOCATION_ID
	JAVA_HOME
	JOURNAL_STREAM
	KDEDIRS
	LANG
	LD_LIBRARY_PATH
	LESSOPEN
	LOGNAME
	LS_COLORS
	MAIL
	MANPATH
	MOZ_ENABLE_WAYLAND
	MOZ_GMP_PATH
	MOZ_WEBRENDER
	NPM_PACKAGES
	PATH
	PWD
	QT_QPA_PLATFORM
	QT_QPA_PLATFORMTHEME
	QT_WAYLAND_DISABLE_WINDOWDECORATION
	SDL_VIDEODRIVER
	SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS
	SHELL
	SHLVL
	SSH_ASKPASS
	STEAM_FRAME_FORCE_CLOSE
	SWAYSOCK
	SYSTEMD_EXEC_PID
	TERM
	TERMCMD
	USER
	WAYLAND_DISPLAY
	WLR_NO_HARDWARE_CURSORS
	XCURSOR_SIZE
	XDG_CACHE_HOME
	XDG_CURRENT_DESKTOP
	XDG_DATA_DIRS
	XDG_RUNTIME_DIR
	XDG_SEAT
	XDG_SESSION_CLASS
	XDG_SESSION_DESKTOP
	XDG_SESSION_ID
	XDG_SESSION_TYPE
	XDG_VTNR
	_
	_JAVA_AWT_WM_NONREPARENTING
	__GLX_VENDOR_LIBRARY_NAME
	npm_config_prefix
	which_declare

Additional context
This obviously only seems relevant if copy_or_interrupt is set, so it makes no sense to use a default config

@kovidgoyal
Copy link
Owner

  1. Post a complete program that reproduces the issue
  2. Build kitty with make asan and post the error you get when reproducing

@page-down
Copy link
Contributor

@kovidgoyal

kitty/screen.c

static PyObject*
extend_tuple(PyObject *a, PyObject *b) {
    Py_ssize_t bs = PyBytes_GET_SIZE(b);
// ...

The parameter b should be tuple here, why do we use PyBytes_GET_SIZE to get the length? Am I missing something?

@kovidgoyal
Copy link
Owner

80fc3a1

@page-down
Copy link
Contributor

What should I do to get a situation where selections->count is greater than 1?
It seems that the count is 1 no matter how the text is selected by mouse.

static PyObject*
text_for_selections(Screen *self, Selections *selections, ... )

@kovidgoyal
Copy link
Owner

You cannot kitty does not currently support multi-select. Though IIRC
you can get multiple url underlines with hyperlinks. That was what this
was added for in the first place.

@page-down
Copy link
Contributor

Steps to reproduce:

  • kitty -o 'map f1 copy_or_interrupt' -o remember_window_size=no -o initial_window_height=5c -o scrollback_lines=10
  • python3 -c "print('\n'*30)" Select some text before pressing Enter.
  • Press F1
static PyObject*
text_for_range(...) {
    IterationData idata;
    iteration_data(self, sel, &idata, -self->historybuf->count, false);
    int limit = MIN((int)self->lines, idata.y_limit);
    // lines: 5, y_limit: -28, y: -24 (min_y: -24)
    // -28 - (-24) -> PyTuple_New(-4)
    PyObject *ans = PyTuple_New(limit - idata.y);

To fix this:

static void
iteration_data(const Screen *self, const Selection *sel, IterationData *ans, int min_y, bool add_scrolled_by) {
// ...
    ans->y = MAX(ans->y, min_y);
    ans->y_limit = MAX(ans->y_limit, ans->y);
}

Maybe there are problems in other places too.
I think the text selection should be cancelled after the text selection block goes out of range.
Otherwise y will probably become positive after exceeds -2147483647.

@kovidgoyal
Copy link
Owner

I'm not a fan off invalidating selections on scroll, one then has to check
the selection at every scroll, and scrolling can be quite fast. Batter
to validate when the selection is used/iterated over

@page-down
Copy link
Contributor

... one then has to check the selection at every scroll, and scrolling can be quite fast ...

The only reason I bring this up is that I see iteration_data being called on every scroll, and even on every mouse-move event, when there is a selection.(regardless of whether the selection is on-screen or not)

My intention is to reduce the unnecessary checks and only do it when needed.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Feb 20, 2022 via email

@page-down
Copy link
Contributor

It looks like the text selection is iterated over (not the content, just iteration_data) when rendering each frame, not just when moving the mouse or scrolling.
Is it possible to ignore the text selection when it is not on screen and the subsequent rendering will quickly skip the check? (Perhaps the performance gain is not worth it.)

If you don't have time, I need to understand the possible impacts involved before I could touch the code.


Should copy_or_interupts interrupt the program when the selected text is not on screen?
I don't think so. In principle, the text should be copied because there is an invisible text selection.

However, when this selection is rolled over several screens (still in the history range), the user may have forgotten and would like to interrupt.
Since in most scenarios, only the selection that is on the current screen needs to be copied.
It might be possible to add an argument for the action to ensure backward compatibility.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Feb 20, 2022 via email

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