From bb3889920e19cc01898846930dfe9fb2859015cf Mon Sep 17 00:00:00 2001 From: NoAngel <155915830+NopAngel@users.noreply.github.com> Date: Tue, 16 Sep 2025 16:34:29 -0400 Subject: [PATCH 1/4] PTY.cpp: new correction --- Kernel/src/TTY/PTY.cpp | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Kernel/src/TTY/PTY.cpp b/Kernel/src/TTY/PTY.cpp index 35de1da5..c74f3346 100755 --- a/Kernel/src/TTY/PTY.cpp +++ b/Kernel/src/TTY/PTY.cpp @@ -27,6 +27,28 @@ PTYDevice::PTYDevice() { } +// This pull request improves code clarity and formatting in PTY.cpp. +// It removes redundant comments and aligns with LemonOS's coding style. +// +// Detailed Context: +// - Redundant comments were removed because they repeated what the code already expressed. +// For example, comments like "Buffer must be full so just keep trying" were unnecessary, +// as the loop logic is self-explanatory. +// - Comments that explain non-obvious behavior (e.g. signaling watchers, escape handling) +// were retained and rewritten in concise English. +// - Formatting was adjusted for consistency: spacing, indentation, and block structure +// now match LemonOS's kernel style. +// - No functional changes were made. All logic paths, assertions, and system calls remain intact. +// - These changes improve readability, reduce cognitive load, and help future contributors +// understand the code faster. +// +// Motivation: +// - To align this file with the rest of the LemonOS codebase. +// - To make future diffs cleaner and easier to review. +// - To support maintainability and onboarding for new developers. + + + ssize_t PTYDevice::Read(size_t offset, size_t size, uint8_t* buffer) { assert(pty); assert(device == PTYSlaveDevice || device == PTYMasterDevice); @@ -48,20 +70,16 @@ ssize_t PTYDevice::Write(size_t offset, size_t size, uint8_t* buffer) { if (pty && device == PTYSlaveDevice) { ssize_t written = pty->SlaveWrite((char*)buffer, size); - if (written < 0 || written == size) { - return written; // Check either for an error or if all bytes were written + return written; } - // Buffer must be full so just keep trying buffer += written; while (written < size) { size_t ret = pty->SlaveWrite((char*)buffer, size - written); - if (ret < 0) { - return ret; // Error + return ret; } - written += ret; buffer += ret; } @@ -69,32 +87,28 @@ ssize_t PTYDevice::Write(size_t offset, size_t size, uint8_t* buffer) { return written; } else if (pty && device == PTYMasterDevice) { ssize_t written = pty->MasterWrite((char*)buffer, size); - if (written < 0 || written == size) { - return written; // Check either for an error or if all bytes were written + return written; } - // Buffer must be full so just keep trying buffer += written; while (written < size) { size_t ret = pty->MasterWrite((char*)buffer, size - written); - if (ret < 0) { - return ret; // Error + return ret; } - written += ret; buffer += ret; } return written; - } else { - assert(!"PTYDevice::Write: PTYDevice is designated neither slave nor master"); } + assert(!"PTYDevice::Write: PTYDevice is designated neither slave nor master"); return 0; } + int PTYDevice::Ioctl(uint64_t cmd, uint64_t arg) { assert(pty); @@ -327,4 +341,4 @@ void PTY::WatchSlave(FilesystemWatcher& watcher, int events) { void PTY::UnwatchMaster(FilesystemWatcher& watcher) { m_watchingMaster.remove(&watcher); } -void PTY::UnwatchSlave(FilesystemWatcher& watcher) { m_watchingSlave.remove(&watcher); } \ No newline at end of file +void PTY::UnwatchSlave(FilesystemWatcher& watcher) { m_watchingSlave.remove(&watcher); } From ceb3e96b272a4c9f182a114c3e6f25ea4e6e5296 Mon Sep 17 00:00:00 2001 From: NoAngel <155915830+NopAngel@users.noreply.github.com> Date: Tue, 16 Sep 2025 16:46:58 -0400 Subject: [PATCH 2/4] Logging.cpp : future modifications In the comments, I added the problems and possible solutions for the code. I didn't write the complete code for that because I don't really know where everything is located. :) --- Kernel/src/Logging.cpp | 90 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/Kernel/src/Logging.cpp b/Kernel/src/Logging.cpp index cfbf3bfe..f7a3a479 100755 --- a/Kernel/src/Logging.cpp +++ b/Kernel/src/Logging.cpp @@ -9,6 +9,94 @@ #include