Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PEP 741] gh-107954: Add PyInitConfig C API#110176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
vstinner wants to merge2 commits intopython:mainfromvstinner:config_set_abi

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedOct 1, 2023
edited
Loading

Add PyInitConfig functions:

  • PyInitConfig_Python_New()
  • PyInitConfig_Isolated_New()
  • PyInitConfig_Free(config)
  • PyInitConfig_SetInt(config, key, value)
  • PyInitConfig_SetStr(config, key, value)
  • PyInitConfig_SetWStr(config, key, value)
  • PyInitConfig_SetStrList(config, key, length, items)
  • PyInitConfig_SetWStrList(config, key, length, items)
  • PyInitConfig_GetErrorMsg(config)

Add also functions using it:

  • Py_InitializeFromInitConfig(config)
  • Py_ExitWithInitConfig(config)

Changes:

  • Add Include/initconfig.h header.

Discussion:https://discuss.python.org/t/fr-allow-private-runtime-config-to-enable-extending-without-breaking-the-pyconfig-abi/18004/20

@vstinner
Copy link
MemberAuthor

@vstinner
Copy link
MemberAuthor

TODO: once we reach an consensus on the API, I will document the API.

@vstinnervstinner marked this pull request as ready for reviewNovember 30, 2023 22:20
@vstinnervstinner requested review froma team andencukou ascode ownersNovember 30, 2023 22:20
@vstinner
Copy link
MemberAuthor

I documented the API. I decided to add a newDoc/c-api/config.rst documentation for that.

Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

Thank you!
Now that I see all the docs, it looks the design is missing a function:https://discuss.python.org/t/fr-allow-private-runtime-config-to-enable-extending-without-breaking-the-pyconfig-abi/18004/49?u=encukou

I also have a few docs nitpicks. I didn't look very closely at the implementation yet.

Comment on lines 94 to 95
Return ``-1`` if Python wants to exit and on error. Call
:c:func:`Py_ExitWithInitConfig` in this case.
Copy link
Member

Choose a reason for hiding this comment

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

What happens if you don't call it? (If it needs to be called, why doesPy_InitializeFromInitConfig not call it itself?)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The idea is to let the caller decide how to handle an error or an exit code. When you embed Python, you may not want the process to exit. It's a similar design thanPy_InitializeFromConfig() and thePyStatus C API.

What happens if you don't call it?

Python is in an undefined state. The error/exit code stays in PyInitConfig. It's safer to handle the init error :-)

@vstinnervstinnerforce-pushed theconfig_set_abi branch 2 times, most recently fromfee8cc4 to7d59519CompareDecember 1, 2023 16:08
@vstinner
Copy link
MemberAuthor

This change is quite big, so I moved PyConfig_Get() API to a separated PR: PR#112609.

Add PyInitConfig functions:* PyInitConfig_Python_New()* PyInitConfig_Isolated_New()* PyInitConfig_Free(config)* PyInitConfig_SetInt(config, key, value)* PyInitConfig_SetStr(config, key, value)* PyInitConfig_SetWStr(config, key, value)* PyInitConfig_SetStrList(config, key, length, items)* PyInitConfig_SetWStrList(config, key, length, items)* PyInitConfig_Exception(config)* PyInitConfig_GetError(config, &err_msg)* PyInitConfig_GetExitCode(config, &exitcode)Add also functions using it:* Py_InitializeFromInitConfig(config)* Py_ExitWithInitConfig(config)Add these functions to the limited C API.Changes:* Add Doc/c-api/config.rst.* Add Include/initconfig.h header.
@vstinner
Copy link
MemberAuthor

This API is kind of complicated (there are multiple use cases). I created PR#112609 as a starting point, just to add two functions. But apparently, adding PyConfig_Get() and PyConfig_GetInt() functions is more complicated than what I expected. I don't have the bandwidth to deal with such large API for now, so I prefer to close the PR. See also mycomment on the PyConfig_Get() PR.

@vstinnervstinner deleted the config_set_abi branchDecember 20, 2023 11:09
@vstinnervstinner restored the config_set_abi branchFebruary 7, 2024 02:04
@vstinnervstinner changed the titlegh-107954: Add PyInitConfig C API[PEP 741] gh-107954: Add PyInitConfig C APIMay 3, 2024
@vstinner
Copy link
MemberAuthor

New PR:#123502

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

Reviewers

@encukouencukouencukou left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@encukou

[8]ページ先頭

©2009-2025 Movatter.jp