Skip to content

[200_22] 修复read-line无法检测到Ctrl+D的问题#659

Merged
da-liii merged 1 commit intomainfrom
da/200_22/read-line-ctrl-d
Apr 3, 2026
Merged

[200_22] 修复read-line无法检测到Ctrl+D的问题#659
da-liii merged 1 commit intomainfrom
da/200_22/read-line-ctrl-d

Conversation

@da-liii
Copy link
Copy Markdown
Contributor

@da-liii da-liii commented Apr 3, 2026

No description provided.

@da-liii da-liii merged commit 53032b0 into main Apr 3, 2026
4 checks passed
@da-liii da-liii deleted the da/200_22/read-line-ctrl-d branch April 3, 2026 06:14
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR fixes a one-line bug in src/s7.c where stdin_read_line was returning nil_string (the empty string "") instead of eof_object when fgets returned NULL (i.e., when Ctrl+D / EOF was pressed on stdin). This made (eof-object? (read-line)) always return #f when reading from stdin, breaking the R7RS contract for read-line.

Key changes:

  • In stdin_read_line, the fallback return value is changed from nil_string to eof_object, making it consistent with file_read_line which already returns eof_object in the same situation.
  • No new tests are added specifically for stdin EOF detection (existing tests in tests/scheme/base/read-line-test.scm only cover string ports).

Confidence Score: 5/5

This PR is safe to merge — it is a minimal, targeted one-line fix that aligns stdin_read_line with the existing behavior of file_read_line and the R7RS standard.

The change is a single-line fix with clear motivation: fgets returning NULL means EOF (or error), and the correct R7RS return value is the EOF object, not an empty string. The same pattern already exists in file_read_line (line 26958), so this is simply making stdin_read_line consistent. No regressions are expected.

No files require special attention. The change is isolated to a single return statement in stdin_read_line.

Important Files Changed

Filename Overview
src/s7.c One-line fix: stdin_read_line now returns eof_object instead of nil_string when fgets returns NULL, consistent with file_read_line and R7RS semantics.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["read-line called"] --> B{"Port type?"}
    B -->|stdin| C["stdin_read_line()"]
    B -->|file| D["file_read_line()"]
    B -->|string| E["string_read_line()"]

    C --> F["fgets(buf, size, stdin)"]
    F -->|"returns non-NULL"| G["return s7_make_string(buf)"]
    F -->|"returns NULL (Ctrl+D / EOF)"| H["return eof_object ✅\n(previously: nil_string ❌)"]

    D --> I["fgets(buf, size, file)"]
    I -->|"returns non-NULL"| J["parse until newline,\nreturn string"]
    I -->|"returns NULL (EOF/error)"| K["return eof_object"]

    style H fill:#d4edda,stroke:#28a745
Loading

Reviews (1): Last reviewed commit: "[200_22] 修复read-line无法检测到Ctrl+D的问题" | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant