Skip to content

Commit

Permalink
Merge pull request #157 from hartwork/fix-for-o1
Browse files Browse the repository at this point in the history
 Fix crash with `-O1` on Ctrl+C + address `-O1` warnings + make CI compile with `-O1`
  • Loading branch information
tenox7 authored Dec 26, 2023
2 parents 375d195 + aa919c9 commit 19972f3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_and_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
${MAKE} --version 2>/dev/null || true
CFLAGS="-std=gnu99 -pedantic -Werror ${sanitizer}" LDFLAGS="${as_needed} ${sanitizer}" ${MAKE}
CFLAGS="-std=gnu99 -pedantic -Werror ${sanitizer} -O1" LDFLAGS="${as_needed} ${sanitizer}" ${MAKE}
- name: 'Install'
env:
Expand Down
6 changes: 3 additions & 3 deletions recordings/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
| │ |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X Thu Jan 1 00:00:00 1970 |
|   https://github.com/tenox7/ttyplot 1.6.0 |
|   https://github.com/tenox7/ttyplot 1.6.1 |
+------------------------------------------------------------------------------------------+

[90x20] Frame 2:
Expand All @@ -43,7 +43,7 @@
| │ XX |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.0 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.1 |
+------------------------------------------------------------------------------------------+

[90x20] Frame 3:
Expand All @@ -67,6 +67,6 @@
| │ XX |
| └─────────────────────────────────────────────────────────────────────────────────────> |
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.0 |
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.1 |
+------------------------------------------------------------------------------------------+

2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ttyplot
version: 1.6.0
version: 1.6.1
summary: realtime plotting utility for terminal/console with data input from stdin
description: |
takes data from standard input / unix pipeline,
Expand Down
12 changes: 8 additions & 4 deletions stresstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,20 @@ int main(int argc, char *argv[]) {
size_t send_pos = 0;
while (buffer_pos - send_pos >= 16) {
const size_t bytes_to_send = 1 + rand() % 16; // 1..16
write(STDOUT_FILENO, buffer + send_pos, bytes_to_send);
const ssize_t bytes_sent = write(STDOUT_FILENO, buffer + send_pos, bytes_to_send);
usleep(50); // let ttyplot read this before proceeding
send_pos += bytes_to_send;
if (bytes_sent > 0)
send_pos += bytes_sent;
}
if (send_pos > 0 && send_pos < buffer_pos)
memmove(buffer, buffer + send_pos, buffer_pos - send_pos);
buffer_pos -= send_pos;
} else {
write(STDOUT_FILENO, buffer, buffer_pos);
buffer_pos = 0;
const ssize_t bytes_sent = write(STDOUT_FILENO, buffer, buffer_pos);
if ((bytes_sent > 0) && ((size_t)bytes_sent < buffer_pos))
memmove(buffer, buffer + bytes_sent, buffer_pos - bytes_sent);
if (bytes_sent > 0)
buffer_pos -= bytes_sent;
}
usleep(delay);
}
Expand Down
2 changes: 1 addition & 1 deletion ttyplot.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd November 27, 2023
.Dd December 25, 2023
.Dt TTYPLOT 1
.Os
.Sh NAME
Expand Down
9 changes: 6 additions & 3 deletions ttyplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define STR(x) STR_(x)
#define VERSION_MAJOR 1
#define VERSION_MINOR 6
#define VERSION_PATCH 0
#define VERSION_PATCH 1
#define VERSION_STR STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_PATCH)

#define T_RARR '>'
Expand Down Expand Up @@ -282,7 +282,10 @@ static void paint_plot(void) {
// (Related: https://stackoverflow.com/q/62315082)
static void signal_handler(int signum) {
const unsigned char signal_number = (unsigned char) signum; // signum is either 2 (SIGINT) or 28 (SIGWINCH)
write(signal_write_fd, &signal_number, 1);
ssize_t write_res;
do {
write_res = write(signal_write_fd, &signal_number, 1);
} while ((write_res == -1) && (errno == EINTR));
}

static void redraw_screen(const char * errstr) {
Expand Down Expand Up @@ -478,7 +481,7 @@ static int wait_for_events(int signal_read_fd, int tty, bool stdin_is_open, stru
ret |= EVENT_SIGNAL_READABLE;
}

if (FD_ISSET(tty, &read_fds)) {
if ((tty != -1) && FD_ISSET(tty, &read_fds)) {
ret |= EVENT_TTY_READABLE;
}

Expand Down

0 comments on commit 19972f3

Please sign in to comment.