Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-14 Thread Martin v. Löwis
Jeremy Hylton wrote: >>Perhaps there is some value in finding functions which ought to expect >>const char*. For that, occasional checks should be sufficient; I cannot >>see a point in having code permanently pass with that option. In >>particular not if you are interfacing with C libraries. > >

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-14 Thread Jeremy Hylton
On 2/14/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > Jeremy Hylton wrote: > > The compiler in question is gcc and the warning can be turned off with > > -Wno-write-strings. I think we'd be better off leaving that option > > on, though. This warning will help me find places where I'm passing

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-14 Thread Jeremy Hylton
On 2/14/06, M.-A. Lemburg <[EMAIL PROTECTED]> wrote: > Martin v. Löwis wrote: > > M.-A. Lemburg wrote: > >>> It's the consequences: nobody complains about tacking "const" on to a > >>> former honest-to-God "char *" argument that was in fact not modified, > >>> because that's not only helpful for C

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-14 Thread Jack Jansen
Thanks to all for a rather insightful discussion, it's always fun to learn that after 28 years of C programming the language still has little corners that I know absolutely nothing about:-) Practically speaking, though, I've adopted MAL's solution for the time being: > /* The keyword array

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-14 Thread M.-A. Lemburg
Martin v. Löwis wrote: > M.-A. Lemburg wrote: >>> It's the consequences: nobody complains about tacking "const" on to a >>> former honest-to-God "char *" argument that was in fact not modified, >>> because that's not only helpful for C++ programmers, it's _harmless_ >>> for all programmers. For e

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Martin v. Löwis
M.-A. Lemburg wrote: >>It's the consequences: nobody complains about tacking "const" on to a >>former honest-to-God "char *" argument that was in fact not modified, >>because that's not only helpful for C++ programmers, it's _harmless_ >>for all programmers. For example, nobody could sanely objec

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Martin v. Löwis
Jeremy Hylton wrote: > The compiler in question is gcc and the warning can be turned off with > -Wno-write-strings. I think we'd be better off leaving that option > on, though. This warning will help me find places where I'm passing a > string literal to a function that does not take a const char

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread M.-A. Lemburg
Tim Peters wrote: > [Jeremy] I added some const to several API functions that take char* but typically called by passing string literals. > > [Tim] >>> If he had _stuck_ to that, we wouldn't be having this discussion :-) >>> (that is, nobody passes string literals to >>> PyArg_ParseTuple

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Jeremy Hylton
On 2/10/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > Jeremy Hylton wrote: > > Ok. I reviewed the original problem and you're right, the problem was > > not that it failed outright but that it produced a warning about the > > deprecated conversion: > > warning: deprecated conversion from stri

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Guido van Rossum
+1 On 2/13/06, Jeremy Hylton <[EMAIL PROTECTED]> wrote: > It sounds like the right answer for Python is to change the signature > of PyArg_ParseTupleAndKeywords() back. We'll fix it when C fixes its > const rules . > > Jeremy > > On 2/13/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > On 2/12

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Jeremy Hylton
It sounds like the right answer for Python is to change the signature of PyArg_ParseTupleAndKeywords() back. We'll fix it when C fixes its const rules . Jeremy On 2/13/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 2/12/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > > > [A large head-explodi

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-13 Thread Guido van Rossum
On 2/12/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > > [A large head-exploding set of rules] > > Blarg. > > Const - Just Say No. +1 -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-Dev mailing list Python-Dev@python.org http:/

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-12 Thread Greg Ewing
Martin v. Löwis wrote: > then, in C++, 4.4p4 [conv.qual] has a rather longish formula to > decide that the assignment is well-formed. In essence, it goes > like this: > > [A large head-exploding set of rules] Blarg. Const - Just Say No. Greg ___ Pyt

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Armin Rigo wrote: > Alas, this doesn't make gcc happy either. (I'm trying gcc 3.4.4.) In > theory, it prevents the const-bypassing trick showed by Martin, but > apparently the C standard (or gcc) is not smart enough to realize that. It appears to be language-defined. Looking at the assignment

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Greg Ewing wrote: > There are *already* differences which make C and C++ > annoyingly incompatible. One is the const char * const * > issue that appeared here. Of course there are differences. C++ has classes, C doesn't. C++ has function overloading, C doesn't. C++ has assignment from char** to c

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Aahz wrote: >>That future version might get published in 2270, when everybody has >>switched to C++, and compatibility with C is no longer required. > > > Just for the clarification of those of us who are not C/C++ programmers, > are you saying that this is different from the meaning in Python, w

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Greg Ewing
Martin v. Löwis wrote: > That future version might get published in 2270, There are *already* differences which make C and C++ annoyingly incompatible. One is the const char * const * issue that appeared here. Another is that it no longer seems to be permissible to forward-declare static things,

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Armin Rigo
Hi Tim, On Fri, Feb 10, 2006 at 12:19:01PM -0500, Tim Peters wrote: > Oh, who cares? I predict "Jack's problem" would go away if we changed > the declaration of PyArg_ParseTupleAndKeywords to what you intended > to begin with: > > PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Bengt Richter
On Sat, 11 Feb 2006 14:14:00 +0100, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Will a typedef help? > >A typedef can never help. It is always possible to reformulate >a program using typedefs to one that doesn't use typedefs. I realize that's tr

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Aahz
On Sat, Feb 11, 2006, "Martin v. L?wis" wrote: > > Not at all. People appear to completely fail to grasp the notion of > "deprecated" in this context. It just means "it may go away in a > future version", implying that the rest of it may *not* go away in a > future version. > > That future version

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Bengt Richter wrote: > Will a typedef help? A typedef can never help. It is always possible to reformulate a program using typedefs to one that doesn't use typedefs. Compiling your program with the const modification line removed gives martin.c: In function 'int main()': martin.c:18: error: inva

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Bengt Richter
On Fri, 10 Feb 2006 18:02:03 +0100, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >Jeremy Hylton wrote: >> 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

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Bengt Richter wrote: > Would it make sense to use a typedef for readability's sake? E.g., > > typedef const char * p_text_literal; > > and then use > > p_text_literal, const p_text_literal * > > in the signature, for read-only access to the data? (hope I got that right). > > (also test

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-11 Thread Martin v. Löwis
Greg Ewing wrote: >>FWIW, Annex D also defines these features as deprecated: >>- the use of "static" for objects in namespace scope (AFAICT >> including C file-level static variables and functions) >>- C library headers (i.e. ) > > > Things like this are really starting to get on my groat. > It

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Bengt Richter
On Fri, 10 Feb 2006 17:53:39 +0100, Thomas Wouters <[EMAIL PROTECTED]> wrote: >On Fri, Feb 10, 2006 at 11:30:30AM -0500, Jeremy Hylton wrote: >> On 2/10/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: >> > OMG. Are we now adding 'const' modifiers to random places? I thought >> > "const propagation

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Greg Ewing
Martin v. Löwis wrote: > FWIW, Annex D also defines these features as deprecated: > - the use of "static" for objects in namespace scope (AFAICT > including C file-level static variables and functions) > - C library headers (i.e. ) Things like this are really starting to get on my groat. It use

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Martin v. Löwis
Tim Peters wrote: >>Sigh. I don't see any way to avoid a warning in Jack's case. > > > Martin's turn ;-) I see two options: 1. Revert the change for the const char** keywords argument (but leave the change for everything else). C++ users should only see a problem if they have a const cha

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Martin v. Löwis
Jeremy Hylton wrote: > Ok. I reviewed the original problem and you're right, the problem was > not that it failed outright but that it produced a warning about the > deprecated conversion: > warning: deprecated conversion from string constant to 'char*'' > > I work at a place that takes the same

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
On 2/10/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 2/10/06, Tim Peters <[EMAIL PROTECTED]> wrote: > > [Jeremy] > > I added some const to several API functions that take char* but > > typically called by passing string literals. > > > > If he had _stuck_ to that, we wouldn't be

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Tim Peters
[Jeremy] >>> I added some const to several API functions that take char* but >>> typically called by passing string literals. [Tim] >> If he had _stuck_ to that, we wouldn't be having this discussion :-) >> (that is, nobody passes string literals to >> PyArg_ParseTupleAndKeywords's kws argument).

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Guido van Rossum
On 2/10/06, Tim Peters <[EMAIL PROTECTED]> wrote: > [Jeremy] > >> 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 inc

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
On 2/10/06, Tim Peters <[EMAIL PROTECTED]> wrote: > [Jeremy] > I added some const to several API functions that take char* but > typically called by passing string literals. > > If he had _stuck_ to that, we wouldn't be having this discussion :-) > (that is, nobody passes string literal

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Tim Peters
[Jeremy] >> 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, >>

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Guido van Rossum
On 2/10/06, Jeremy Hylton <[EMAIL PROTECTED]> wrote: > 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.

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Tim Peters
[Jeremy] >> It looks like a solution may be to define it as "const char * const *" >> rather than "const char **". I'll see if that works. [Jeremy] > No. It doesn't work. I'm not sure about this one either, but some > searching suggests that you can pass a char** to a function taking > const ch

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
On 2/10/06, Jeremy Hylton <[EMAIL PROTECTED]> wrote: > It looks like a solution may be to define it as "const char * const *" > rather than "const char **". I'll see if that works. No. It doesn't work. I'm not sure about this one either, but some searching suggests that you can pass a char** to

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Tim Peters
[Jeremy Hylton] > ... > 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 probl

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
On 2/10/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > Jeremy Hylton wrote: > > 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, >

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Martin v. Löwis
Jeremy Hylton wrote: > 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, That's not true. A string literal of length N is of type const c

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
It looks like a solution may be to define it as "const char * const *" rather than "const char **". I'll see if that works. Jeremy On 2/10/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > Jeremy Hylton wrote: > > I admit that I'm also puzzled by Jack's specific question. I don't > > understan

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Martin v. Löwis
Jeremy Hylton wrote: > 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 proble

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Thomas Wouters
On Fri, Feb 10, 2006 at 11:30:30AM -0500, Jeremy Hylton wrote: > 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

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Jeremy Hylton
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* b

Re: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification

2006-02-10 Thread Guido van Rossum
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? --Guido On 2/10/06, Jack Jansen <[EMAIL PROTECTED]> wrote: > I keep running into problems with the "const" modifications t