GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-123018: Keep the libedit history file header when truncating by gpshead · Pull Request #157165 · python/cpython

Conversation

@gpshead

@gpshead gpshead commented Sep 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

libedit's history_truncate_file() keeps the last N lines of the file, which drops the "_HiStOrY_V2_" header line that its own write_history() emits and that its read_history() requires. So on a libedit build, readline.write_history_file() or readline.append_history_file() after readline.set_history_length() produced a file that readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the header, resolving the default "~/.history" the same way libedit does. Apple's libedit fork already preserves the header, so the workaround is not compiled on macOS.

  • Issue: Python limited history test fails when configured to use editline instead of readline #123018

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Sep 8, 2026
Python limited history test fails when configured to use editline instead of readline #123018
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 8, 2026
@gpshead gpshead added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Sep 8, 2026
@gpshead gpshead self-assigned this Sep 8, 2026
@gpshead gpshead mentioned this pull request Sep 8, 2026
readline.set_history_length corrupts history files when used in a libedit build #121160
Closed
gpshead
gpshead commented Sep 8, 2026
View reviewed changes
Comment thread Modules/readline.c
static int
_py_libedit_history_truncate_file(const char *filename, int nlines)
{
static const char cookie[] = "_HiStOrY_V2_\n";

@gpshead gpshead Sep 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

over in #121160 the earlier choice was not to do a workaround because it seemed fragile. yes this PR intentionally decides the other way. libedit is not likely to change or a fix to it become widely distributed any time soon. apple patched theirs rather than push on upstream. if netbsd libedit does adopt a new history format version, this marker won't match and this function basically becomes a no-op that does nothing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gpshead gpshead Sep 8, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like someone did at least file a NetBSD bug this year https://gnats.netbsd.org/60322

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gpshead
gpshead force-pushed the fix-editline-tests branch from 9ac2d9c to 39d13be Compare September 8, 2026 05:25
@gpshead
pythongh-123018: Keep the libedit history file header when truncating
9b6d270
libedit's history_truncate_file() keeps the last N lines of the file,
which drops the "_HiStOrY_V2_" header line that its own write_history()
emits and that its read_history() requires.  So on a libedit build,
readline.write_history_file() or readline.append_history_file() after
readline.set_history_length() produced a file that
readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the
header, resolving the default "~/.history" the same way libedit does.
Apple's libedit fork already preserves the header, so the workaround is
not compiled on macOS.
@gpshead
gpshead force-pushed the fix-editline-tests branch from 39d13be to 9b6d270 Compare September 8, 2026 05:58
@gpshead
gpshead enabled auto-merge (squash) September 8, 2026 05:58
@gpshead
gpshead merged commit 2638785 into python:main Sep 8, 2026
54 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Sep 8, 2026
@miss-islington-app

miss-islington-app Bot commented Sep 8, 2026

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Sep 8, 2026

Copy link
Copy Markdown

GH-157172 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Sep 8, 2026
@miss-islington-app

miss-islington-app Bot commented Sep 8, 2026

Copy link
Copy Markdown

Sorry, @gpshead, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 26387858990674f8cd20566f89c700fa1de5d829 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Sep 8, 2026

Copy link
Copy Markdown

GH-157173 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 8, 2026
@whitequark

whitequark commented Sep 8, 2026

Copy link
Copy Markdown

Yay! Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead added a commit that referenced this pull request Sep 9, 2026
@miss-islington @gpshead
[3.14] gh-123018: Keep the libedit history file header when truncating (
e87da80
GH-157165) (#157173)

gh-123018: Keep the libedit history file header when truncating (GH-157165)

libedit's history_truncate_file() keeps the last N lines of the file,
which drops the "_HiStOrY_V2_" header line that its own write_history()
emits and that its read_history() requires.  So on a libedit build,
readline.write_history_file() or readline.append_history_file() after
readline.set_history_length() produced a file that
readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the
header, resolving the default "~/.history" the same way libedit does.
Apple's libedit fork already preserves the header, so the workaround is
not compiled on macOS.
(cherry picked from commit 2638785)

Co-authored-by: Gregory P. Smith <[email protected]>
maurycy added a commit to maurycy/cpython that referenced this pull request Sep 10, 2026
@maurycy
Merge branch 'main' into tachyon-native-callable
e028ff5
* main: (158 commits)
  pythongh-156924: Try reifying lazy imports in `ForwarRef.evaluate()` (python#156940)
  pythongh-156233: Fix typos and code snippet errors in the docs (python#156475)
  pythongh-156837: Refer to yield expressions in generator function definitions (pythonGH-156863)
  pythongh-155292: Skip updating unicodedata with mismatched interpreter (pythonGH-157066)
  pythongh-157170: Document the scope of global curses settings (pythonGH-157207)
  pythongh-155966: Correct handling of `math.tanpi` poles (python#155980)
  pythongh-157170: Restore use_env() after test_use_prescr_screen in test_curses (pythonGH-157171)
  pythongh-156910: fix deadlock in type_set_abstractmethods under free-threading (python#156948)
  pythongh-155648: Write the empty and placeholder IDLE tests (python#156260)
  pythongh-153569: centralize formatted-string state and source spans (python#156484)
  pythongh-157137: Mark the PEP 820 soft deprecations as 3.15, not `next` (python#157138)
  pythongh-152433: Use regular LoadLibrary in UWP for Windows system libs (pythonGH-156972)
  pythongh-121617: Fix Py_CLEAR() memcpy in C++: replace NULL with _Py_NULL (python#157188)
  pythongh-157135: Fix documentation errors in the `math.atan{2}pi` functions (python#157136)
  pythongh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (python#157067)
  pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
  pythongh-156109: Allow static, non-framework iOS builds (python#156110)
  pythongh-156780: Emscripten: add missing EM_JS_DEPS (python#156798)
  pythongh-152936: Make privileged functions available on Android (python#152977)
  pythongh-123018: Keep the libedit history file header when truncating (pythonGH-157165)
  ...
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@gpshead @clin1234
pythongh-123018: Keep the libedit history file header when truncating (…
714434d
…pythonGH-157165)

libedit's history_truncate_file() keeps the last N lines of the file,
which drops the "_HiStOrY_V2_" header line that its own write_history()
emits and that its read_history() requires.  So on a libedit build,
readline.write_history_file() or readline.append_history_file() after
readline.set_history_length() produced a file that
readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the
header, resolving the default "~/.history" the same way libedit does.
Apple's libedit fork already preserves the header, so the workaround is
not compiled on macOS.
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
@gpshead @johnslavik
pythongh-123018: Keep the libedit history file header when truncating (…
21db1b7
…pythonGH-157165)

libedit's history_truncate_file() keeps the last N lines of the file,
which drops the "_HiStOrY_V2_" header line that its own write_history()
emits and that its read_history() requires.  So on a libedit build,
readline.write_history_file() or readline.append_history_file() after
readline.set_history_length() produced a file that
readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the
header, resolving the default "~/.history" the same way libedit does.
Apple's libedit fork already preserves the header, so the workaround is
not compiled on macOS.
@hmaarrfk hmaarrfk mentioned this pull request Sep 22, 2026
Build the readline module against libedit instead of GNU readline conda-forge/python-feedstock#936
Merged
4 tasks
gpshead added a commit that referenced this pull request Oct 10, 2026
@miss-islington @gpshead
[3.15] gh-123018: Keep the libedit history file header when truncating (
d59ff39
GH-157165) (#157172)

gh-123018: Keep the libedit history file header when truncating (GH-157165)

libedit's history_truncate_file() keeps the last N lines of the file,
which drops the "_HiStOrY_V2_" header line that its own write_history()
emits and that its read_history() requires.  So on a libedit build,
readline.write_history_file() or readline.append_history_file() after
readline.set_history_length() produced a file that
readline.read_history_file() rejected with EINVAL.

Under the libedit emulation, truncate the file ourselves and keep the
header, resolving the default "~/.history" the same way libedit does.
Apple's libedit fork already preserves the header, so the workaround is
not compiled on macOS.
(cherry picked from commit 2638785)

Co-authored-by: Gregory P. Smith <[email protected]>
@StanFromIreland StanFromIreland removed the needs backport to 3.13 only security fixes label Oct 12, 2026
@rossburton

rossburton commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I think this is responsible for a test failure when using musl+libeditline #159424.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@gpshead @whitequark @rossburton @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.