Repository navigation
PyArg_ParseTupleAndKeywords doesn't take const char *keywords[] #65210
Description
Activity
This really annoys me. I have to store the literals in char[] and then make a char*[] from them. It would be better if a simple array of string literals could be used. It would also require less data space because string literals could be merged by the compiler.
I don't know why PyArg_ParseTupleAndKeywords would ever modify the keywords array so it makes absolutely no sense to me for the array not to be const char*[].
In all cases I have seen PyArg_ParseTupleAndKeywords being used string literals were converted to char* (dropping const) which is far far worse than inefficient code.
- addedperformancePerformance or resource usagePerformance or resource usageextension-modulesC modules in the Modules dirC modules in the Modules dir
on Mar 21, 2014 This has come up before. Links to additional info:
https://mail.python.org/pipermail/python-dev/2006-February/060689.html
I think we can't fix this until Python 4.
May I close this issue as "won't fix" for now?Or can we add "Python 4" keyword to list backward incompatible changes we want to do in the future?
We can't change this API because this would break virtually all user code.
But we can introduce a macro like PY_SSIZE_T_CLEAN. If it is defined before including Python.h, PyArg_ParseTupleAndKeywords() will take an array of const strings. This will help for compatibility with C++.
- addedtype-featureA feature request or enhancementA feature request or enhancementand removedperformancePerformance or resource usagePerformance or resource usage
on Jul 3, 2018 - added and removedextension-modulesC modules in the Modules dirC modules in the Modules dir3.8 (EOL)end of lifeend of life
on May 14, 2023 We can fix this at least for C++, because in C++ the
const char * const *declaration is compatible with arguments of typeconst char * const *,char * const *,const char **, andchar **.Sad, it is not so in C, but we can provide a lever to control the declaration, and may change the default in distant future.
- added a commit that references this issue
on Dec 4, 2023 - added a commit that references this issue
on Feb 11, 2024
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs