Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyArg_ParseTupleAndKeywords doesn't take const char *keywords[] #65210

Closed
hvenev mannequin opened this issue Mar 21, 2014 · 5 comments
Closed

PyArg_ParseTupleAndKeywords doesn't take const char *keywords[] #65210

hvenev mannequin opened this issue Mar 21, 2014 · 5 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@hvenev
Copy link
Mannequin

hvenev mannequin commented Mar 21, 2014

BPO 21011
Nosy @methane, @serhiy-storchaka, @MojoVampire, @hvenev

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:

assignee = None
closed_at = None
created_at = <Date 2014-03-21.16:45:16.140>
labels = ['extension-modules', 'type-feature', '3.8']
title = "PyArg_ParseTupleAndKeywords doesn't take const char *keywords[]"
updated_at = <Date 2018-07-03.09:45:24.075>
user = 'https://github.com/hvenev'

bugs.python.org fields:

activity = <Date 2018-07-03.09:45:24.075>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2014-03-21.16:45:16.140>
creator = 'h.venev'
dependencies = []
files = []
hgrepos = []
issue_num = 21011
keywords = []
message_count = 4.0
messages = ['214388', '214857', '320945', '320952']
nosy_count = 4.0
nosy_names = ['methane', 'serhiy.storchaka', 'josh.r', 'h.venev']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue21011'
versions = ['Python 3.8']

Linked PRs

@hvenev
Copy link
Mannequin Author

hvenev mannequin commented 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.

@hvenev hvenev mannequin added performance Performance or resource usage extension-modules C modules in the Modules dir labels Mar 21, 2014
@MojoVampire
Copy link
Mannequin

MojoVampire mannequin commented Mar 25, 2014

@methane
Copy link
Member

methane commented 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?

@methane methane added the 3.8 (EOL) end of life label Jul 3, 2018
@serhiy-storchaka
Copy link
Member

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++.

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement and removed performance Performance or resource usage labels Jul 3, 2018
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added topic-C-API and removed extension-modules C modules in the Modules dir 3.8 (EOL) end of life labels May 14, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 21, 2023
Change the declaration of the keywords parameter in functions
PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() from `char **`
to `char * const *` in C and `const char * const *` in C++.

It makes these functions compatible with argument of type `const char * const *`,
`const char **` or `char * const *` in C++ and `char * const *` in C
without explicit type cast.
@serhiy-storchaka
Copy link
Member

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.

serhiy-storchaka added a commit that referenced this issue Dec 4, 2023
…-105958)

Change the declaration of the keywords parameter in functions
PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() from `char **`
to `char * const *` in C and `const char * const *` in C++.

It makes these functions compatible with argument of type `const char * const *`,
`const char **` or `char * const *` in C++ and `char * const *` in C
without explicit type cast.

Co-authored-by: C.A.M. Gerlach <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…() (pythonGH-105958)

Change the declaration of the keywords parameter in functions
PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() from `char **`
to `char * const *` in C and `const char * const *` in C++.

It makes these functions compatible with argument of type `const char * const *`,
`const char **` or `char * const *` in C++ and `char * const *` in C
without explicit type cast.

Co-authored-by: C.A.M. Gerlach <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…() (pythonGH-105958)

Change the declaration of the keywords parameter in functions
PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() from `char **`
to `char * const *` in C and `const char * const *` in C++.

It makes these functions compatible with argument of type `const char * const *`,
`const char **` or `char * const *` in C++ and `char * const *` in C
without explicit type cast.

Co-authored-by: C.A.M. Gerlach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants