classification
Title: [RFC] PyMemberDef.name should be const char *
Type: compile error Stage:
Components: Extension Modules Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Sunyeop Lee, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-04-11 04:34 by Sunyeop Lee, last changed 2017-04-14 17:56 by serhiy.storchaka.

Files
File name Uploaded Description Edit
test.cpp Sunyeop Lee, 2017-04-11 04:34 c++ source code to reproduce the problem
Messages (2)
msg291459 - (view) Author: Sunyeop Lee (Sunyeop Lee) * Date: 2017-04-11 04:34
PyMemberDef from Noddy examaple: https://docs.python.org/3/extending/newtypes.html

static PyMemberDef Noddy_members[] = {
    {"first", T_OBJECT_EX, offsetof(Noddy, first), 0,
     "first name"},
    {"last", T_OBJECT_EX, offsetof(Noddy, last), 0,
     "last name"},
    {"number", T_INT, offsetof(Noddy, number), 0,
     "noddy number"},
    {NULL}  /* Sentinel */
};

When compiling the code with the PyMemberDef above with GCC, it compiles well. However, with G++, ISO C++11 complains(warns) it is deprecated to convert string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]

Should the example code be fixed, or should PyMemberDef fixed? I think PyMemberDef.name should bo const char * instead of char *.

Compiled with:
g++ test.cpp -I/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/include/python3.6m -L/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin -lpython3.6m -fPIC -shared

Compiler versions:

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
msg291676 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-14 17:56
PyMemberDef.name already is "const char *" in 3.7 (see issue28761).

Adding the const qualifier in other branches can break existing code that assigns PyMemberDef.name to a variable of type "char *". This is not appropriate for bugfix releases.
History
Date User Action Args
2017-04-14 17:56:22serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg291676
2017-04-11 04:34:45Sunyeop Leecreate