On 2/10/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > OMG. Are we now adding 'const' modifiers to random places? I thought > "const propagation hell" was a place we were happily avoiding by not > falling for that meme. What changed?
I added some const to several API functions that take char* but typically called by passing string literals. In C++, a string literal is a const char* so you need to add a const_cast<> to every call site, which is incredibly cumbersome. After some discussion on python-dev, I made changes to a small set of API functions and chased the const-ness the rest of the way, as you would expect. There was nothing random about the places const was added. I admit that I'm also puzzled by Jack's specific question. I don't understand why an array passed to PyArg_ParseTupleAndKeywords() would need to be declared as const. I observed the problem in my initial changes but didn't think very hard about the cause of the problem. Perhaps someone with better C/C++ standards chops can explain. Jeremy > > --Guido > > On 2/10/06, Jack Jansen <[EMAIL PROTECTED]> wrote: > > I keep running into problems with the "const" modifications to > > PyArg_ParseTupleAndKeywords() (rev. 41638 by Jeremy). > > > > I have lots of code of the form > > char *kw[] = {"itself", 0}; > > > > if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, > > CFTypeRefObj_Convert, &itself)) ... > > which now no longer compiles, neither with C nor with C++ (gcc4, both > > MacOSX and Linux). Changing the kw declaration to "const char *kw[]" > > makes it compile again. > > > > I don't understand why it doesn't compile: even though the > > PyArg_ParseTupleAndKeywords signature promises that it won't change > > the "kw" argument I see no reason why I shouldn't be able to pass a > > non-const argument. > > > > And to make matters worse adding the "const" of course makes the code > > non-portable to previous versions of Python (where the C compiler > > rightly complains that I'm passing a const object through a non-const > > parameter). > > > > Can anyone enlighten me? > > -- > > Jack Jansen, <[EMAIL PROTECTED]>, http://www.cwi.nl/~jack > > If I can't dance I don't want to be part of your revolution -- Emma > > Goldman > > > > > > _______________________________________________ > > Python-Dev mailing list > > Python-Dev@python.org > > http://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: > > http://mail.python.org/mailman/options/python-dev/guido%40python.org > > > > > -- > --Guido van Rossum (home page: http://www.python.org/~guido/) > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/jeremy%40alum.mit.edu > _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com