[Python-Dev] Add const to python API - issue 6952
Daniel Stutzbach
daniel at stutzbachenterprises.com
Tue Oct 20 23:31:19 CEST 2009
On Tue, Oct 20, 2009 at 4:03 PM, Barry Scott <barry at barrys-emacs.org> wrote:
> Checking my patch I have two functions that need to
> have output params changed to const to avoid casting.
>
> PyOS_strtoul - ptr
> PyLong_FromString - pend
>
This is a no-win situation. If the string is const in the caller, they
currently need to cast it. If you make the change, then if string is not
const in the caller then they will need to cast it. I've provided a short
example below and marked the lines that generate "an incompatible pointer
type" warning with gcc.
I suggest following POSIX's lead and omitted the const in these cases.
void test_const(const char **foo);
void test_noconst(char **foo);
int main(void) {
char *noconst_var;
const char *const_var;
test_const(&noconst_var); // generates a warning
test_const(&const_var);
test_noconst(&noconst_var);
test_noconst(&const_var); // generates a warning
return 0;
}
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20091020/e9510b10/attachment-0001.htm>
More information about the Python-Dev
mailing list