This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: C API should use 'const char *' instead of 'char *'
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, steveire
Priority: normal Keywords:

Created on 2017-12-14 16:32 by steveire, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg308316 - (view) Author: Stephen Kelly (steveire) Date: 2017-12-14 16:32
When using C++ to extend python, one may use PyGetSetDef for example:


static PyGetSetDef Noddy_getseters[] = {
    {"first",
     (getter)Noddy_getfirst, (setter)Noddy_setfirst,
     "first name",
     NULL},
    {"last",
     (getter)Noddy_getlast, (setter)Noddy_setlast,
     "last name",
     NULL},
    {NULL}  /* Sentinel */
};

However, in C++ implicit conversion from const char* to char* is deprecated since C++98, and is a removed conversion in C++11.

 https://godbolt.org/g/sswUKM

GCC/Clang warn about this, and MSVC in conformance mode (/permissive-) errors on it.

PyGetSetDef and similar APIs should use const char* instead of char* for members such as `name`.
msg308318 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-12-14 16:51
This already was done in issue28761.
History
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76506
2017-12-14 16:51:14serhiy.storchakasetstatus: open -> closed
resolution: out of date
messages: + msg308318

stage: resolved
2017-12-14 16:37:49vstinnersetnosy: + serhiy.storchaka
2017-12-14 16:32:21steveirecreate