You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyArg_ParseTupleAndKeywords doesn't take const char *keywords[]Â #65210
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.
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++.
We can fix this at least for C++, because in C++ the const char * const * declaration is compatible with arguments of type const char * const *, char * const *, const char **, and char **.
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.
Activity
hvenev commentedon Mar 21, 2014
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.
MojoVampire commentedon Mar 25, 2014
This has come up before. Links to additional info:
https://mail.python.org/pipermail/python-dev/2006-February/060689.html
http://bugs.python.org/issue1772673
methane commentedon Jul 3, 2018
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?
serhiy-storchaka commentedon Jul 3, 2018
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++.
pythongh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywords()
serhiy-storchaka commentedon Jun 21, 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.
gh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywords() (GHâĶ
pythongh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywordsâĶ
pythongh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywordsâĶ