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: Compiler warning when compiling dbm module
Type: compile error Stage: resolved
Components: Extension Modules Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, larry, ncoghlan, python-dev, vajrasky
Priority: normal Keywords: patch

Created on 2013-10-19 11:02 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
silent_compiler_warning_dbm_module.patch vajrasky, 2013-10-19 11:02 review
dbm_const_filename.patch christian.heimes, 2013-12-05 17:34 review
Messages (8)
msg200402 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-10-19 11:02
I got this warning when compiling dbm module with Python 3.4.

/home/sky/Code/python/programming_language/cpython/Modules/_dbmmodule.c: In function ‘newdbmobject’:
/home/sky/Code/python/programming_language/cpython/Modules/_dbmmodule.c:55:5: warning: passing argument 1 of ‘dbm_open’ discards ‘const’ qualifier from pointer target type [enabled by default]
In file included from /home/sky/Code/python/programming_language/cpython/Modules/_dbmmodule.c:16:0:
/usr/include/ndbm.h:55:14: note: expected ‘char *’ but argument is of type ‘const char *’

I have two ndbm.h.

/usr/include/ndbm.h
/usr/include/gdbm/ndbm.h

Both of them expect char *file not const char *file in dbm_open.

I downloaded the newest GNU database manager from http://www.gnu.org.ua/software/gdbm/download.html (gdbm-1.10.tar.gz). It expects char *file as well in dbm_open.

Attached the patch to silent the compiler warning.

But when I searched 'dbm_open' in search engines or did "man dbm_open", I got:

DBM *dbm_open(const char *file, int open_flags, mode_t file_mode);

So I am not really sure about this. Feel free to close this ticket if it is not valid.
msg203118 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-17 05:45
I get the same warning on Fedora 19.

However, the signature of dbmopen_impl is generated by argument clinic, so it isn't simply a matter of patching the signature in place. I'm also inclined to consider the *platform* header to be wrong, since the dbm_open API really should be accepting "const char *" rather than "char *".

We should find a way to silence the warning to avoid the false alarm in the build output (a cast to "char *" with a reference to this issue would be the brute force approach), but propagating the incorrect type declaration higher up the call stack is unlikely to be the right approach.
msg205313 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-12-05 17:34
Here is a patch that strncpy() the filename to a char[].
msg205318 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2013-12-05 20:19
Why wouldn't "dbm_open((char *)file, flags, mode)" work?
msg205321 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-12-05 21:26
Yes, a cast to char* silences the error. But it could potentially brea contract because dbm_open() could alter the content of the string. I'm just paranoid (again). *g*
msg205331 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2013-12-05 22:52
I suspect dbm_open predates the common availability of "const".  I assert we can safely assume it won't overwrite the contents of the buffer.  (Barring spectacular memory corruption bugs that "const" would be powerless to prevent.)
msg205335 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-05 23:29
New changeset 3068ff3d9d1e by Christian Heimes in branch 'default':
Issue #19296: Silence compiler warning in dbm_open.
http://hg.python.org/cpython/rev/3068ff3d9d1e
msg205337 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-12-05 23:30
You are probably right. Let's not get too fancy with compiler warnings.
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63495
2013-12-05 23:30:35christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg205337

stage: needs patch -> resolved
2013-12-05 23:29:08python-devsetnosy: + python-dev
messages: + msg205335
2013-12-05 22:52:28larrysetmessages: + msg205331
2013-12-05 21:26:46christian.heimessetmessages: + msg205321
2013-12-05 20:19:00larrysetmessages: + msg205318
2013-12-05 17:34:29christian.heimessetfiles: + dbm_const_filename.patch

nosy: + christian.heimes
messages: + msg205313

type: compile error
stage: needs patch
2013-11-17 05:45:09ncoghlansetnosy: + larry, ncoghlan
messages: + msg203118
2013-10-19 11:02:46vajraskycreate