[New-bugs-announce] [issue32325] C API should use 'const char *' instead of 'char *'

Stephen Kelly report at bugs.python.org
Thu Dec 14 11:32:21 EST 2017


New submission from Stephen Kelly <steveire at gmail.com>:

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

----------
components: Library (Lib)
messages: 308316
nosy: steveire
priority: normal
severity: normal
status: open
title: C API should use 'const char *' instead of 'char *'
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32325>
_______________________________________


More information about the New-bugs-announce mailing list