Skip to content

gh-160962: Fix PyInitConfig_SetStr() with NULL value - #161258

Merged
vstinner merged 6 commits into
python:mainfrom
vstinner:initconfig
Nov 4, 2026
Merged

vstinner merged 6 commits into
python:mainfrom
vstinner:initconfig

Conversation

@vstinner

@vstinner vstinner commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Previously, passing NULL to an optional string option crashed.

Add tests on PyInitConfig_GetInt(), PyInitConfig_GetStr() and PyInitConfig_GetStrList() functions.

Previously, passing NULL to an optional string option crashed.

Add tests on PyInitConfig_GetInt(), PyInitConfig_GetStr() and
PyInitConfig_GetStrList() functions.
@vstinner

vstinner commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

cc @sobolevn @NekoAsakura

@NekoAsakura NekoAsakura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix LGTM.

The tests would be better placed in test_initconfig_get_api(), which already covers the Get* functions. test_initconfig_api is currently skipped on every build (#161270).

Also, the PyInitConfig_SetStr() doc could say that NULL is accepted for optional string options, like PyInitConfig_GetStr() does (link).

Comment thread Programs/_testembed.c Resolved
@vstinner

vstinner commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@NekoAsakura: Please review the updated PR.

The tests would be better placed in test_initconfig_get_api(), which already covers the Get* functions.

Oh, you're right, I completely forgot about test_initconfig_get_api(). I removed redudant tests and completed test_initconfig_get_api() instead.

test_initconfig_api is currently skipped on every build (#161270).

Oops! I approved your PR.

Also, the PyInitConfig_SetStr() doc could say that NULL is accepted for optional string options, like PyInitConfig_GetStr() does (link).

Done: I updated SetStr() doc to mention NULL. I also documented optional strings as str | None type in the Configuration Options table.

@read-the-docs-community

read-the-docs-community Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35630177 | 📁 Comparing 996d0e5 against main (7e3290d)

  🔍 Preview build  

2 files changed
± c-api/init_config.html
± whatsnew/changelog.html

@NekoAsakura NekoAsakura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, LGTM. Just one comment.

Comment thread Programs/_testembed.c Resolved
@vstinner
vstinner enabled auto-merge (squash) November 4, 2026 01:08
@vstinner
vstinner merged commit 6d69297 into python:main Nov 4, 2026
56 checks passed
@vstinner
vstinner deleted the initconfig branch November 4, 2026 01:47
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 4, 2026
@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 4, 2026
vstinner added a commit that referenced this pull request Nov 4, 2026
… (#161291)

gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258)

Previously, passing NULL to an optional string option crashed.

Document optional string options.

Add more tests on the PyInitConfig API.
(cherry picked from commit 6d69297)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Nov 4, 2026
… (#161292)

gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258)

Previously, passing NULL to an optional string option crashed.

Document optional string options.

Add more tests on the PyInitConfig API.
(cherry picked from commit 6d69297)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner

vstinner commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

I merged my PR. Thanks @NekoAsakura for your accurate review!

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.

2 participants