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: Constify C string pointers in the posix module
Type: enhancement Stage: resolved
Components: Extension Modules, Windows Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: eryksun, larry, paul.moore, python-dev, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2016-04-07 06:18 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posixmodule_constify.patch serhiy.storchaka, 2016-04-07 06:18 review
posixmodule_constify2.patch serhiy.storchaka, 2016-05-07 13:17 review
Messages (7)
msg262978 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-07 06:18
Proposed patch adds the "const" qualifier to char and wchar_t pointers in the posix module to prevents possible bugs. These pointers point to internal data of PyBytes or PyUnicode objects or to C string literals, and unintentional changing the content is a hard bug. I expect that the patch can also eliminate some compiler warnings.

Since large part of the code is Windows specific, the patch needs to be tested on Windows.
msg262979 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2016-04-07 06:33
You should find a different reviewer.  I don't really care about "const".  I'll live with it if it's there but I'm not going to go around adding it.
msg265049 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-07 08:09
Could anyone please try to compile with the patch on Windows and report if there are complile errors?
msg265060 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-05-07 11:47
I get the following warnings:

..\Modules\posixmodule.c(7422): warning C4090: 'function': different 'const' qualifiers [...]
..\Modules\posixmodule.c(7423): warning C4090: 'function': different 'const' qualifiers [...]

        target_is_directory |= _check_dirW(src->wide, dst->wide);
        result = Py_CreateSymbolicLinkW(dst->wide, src->wide,
                                        target_is_directory);

..\Modules\posixmodule.c(7429): warning C4090: 'function': different 'const' qualifiers [...]

        result = Py_CreateSymbolicLinkA(dst->narrow, src->narrow,
                                        target_is_directory);

You can change _check_dirW to use LPCWSTR parameters, or const wchar_t * to be consistent with _check_dirA. In this context I prefer the Windows typedefs:

    _check_dirW(LPCWSTR src, LPCWSTR dest)
    _check_dirA(LPCSTR src, LPCSTR dest)

Change Py_CreateSymbolicLink[W|A] to use LPC[W]STR, which is how it's declared in Winbase.h:

    static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD) = NULL;
    static DWORD (CALLBACK *Py_CreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD) = NULL;
msg265067 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-07 13:17
Thank you Eryk. Here is updated patch. Is it correct?
msg265068 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-05-07 13:36
It looks good to me. There are no errors or warnings.
msg265070 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-05-07 13:45
New changeset 7edf74098c76 by Serhiy Storchaka in branch 'default':
Issue #26708: Use the "const" qualifier for immutable strings.
https://hg.python.org/cpython/rev/7edf74098c76
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70895
2016-05-07 13:46:53serhiy.storchakasetstatus: open -> closed
assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2016-05-07 13:45:45python-devsetnosy: + python-dev
messages: + msg265070
2016-05-07 13:36:58eryksunsetmessages: + msg265068
2016-05-07 13:17:42serhiy.storchakasetfiles: + posixmodule_constify2.patch

messages: + msg265067
2016-05-07 11:47:39eryksunsetnosy: + eryksun
messages: + msg265060
2016-05-07 08:09:26serhiy.storchakasetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg265049
components: + Windows
2016-04-07 06:33:07larrysetmessages: + msg262979
2016-04-07 06:18:17serhiy.storchakacreate