Skip to content

Comments

fix: issue 124 unicode sys.argv#127

Merged
Falldog merged 7 commits intomasterfrom
fix/issue-124-unicode-argv
Aug 17, 2025
Merged

fix: issue 124 unicode sys.argv#127
Falldog merged 7 commits intomasterfrom
fix/issue-124-unicode-argv

Conversation

@Falldog
Copy link
Owner

@Falldog Falldog commented Aug 7, 2025

Background

Fix #124
sys.argv should support unicode string as argumnet

Solution

  • Python 3.7 stay in original behavior
  • Python 3.8+ use PyPreConfig & PyConfig to setup argv
  • pyconcrete_exe.c use wmain on Windows platform
  • pyconcrete_exe.c use main on other platform
    • for supporting wmain & main in code, use macro define custom _XXXX to support it at the same logic
  • (Breaking Change) for Python 3.8+, enable utf8_mode by PyPreConfig, ref doc: https://docs.python.org/3/library/os.html#utf8-mode

Not support platform

Windows Python3.7

* use PyDecodeLocale to decode unicode rather than mbstowcs
* windows platform able to get correct encoding char only when use `wmain` to build
* for supporting wmain & main in code, use macro define custom `_XXXX` to support it at the same logic
  * wmain need to use wchar_t version
  * main need to use char version
* PySys_SetArgv is deprecated since python 3.11. It's original behavior will insert script's directory into sys.path.
  It's replace by PyConfig, but PyConfig only update sys.path when executing Py_Main or Py_RunMain.
  So it's better to update sys.path by pyconcrete.
@Falldog Falldog force-pushed the fix/issue-124-unicode-argv branch from 895cc70 to 741e164 Compare August 16, 2025 12:27
[why] PyObject_CallOneArg only support on 3.9+
[how] Replace it by PyObject_CallObject
[why] PyConfig added at 3.8
[how] Use original behavior Py_SetProgramName & PySys_SetArgv
@Falldog Falldog force-pushed the fix/issue-124-unicode-argv branch from 630bd4f to 663350d Compare August 17, 2025 00:46
@Falldog Falldog merged commit 5c6b0c3 into master Aug 17, 2025
14 checks passed
@Falldog Falldog deleted the fix/issue-124-unicode-argv branch August 17, 2025 00:51
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.

sys.argv can not recognize chinese charactor

1 participant