Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-15 Thread Scott Dial
On 10/7/2011 7:13 PM, Terry Reedy wrote: > On 10/7/2011 10:06 AM, Nick Coghlan wrote: >> FWIW, I don't mind whether it's "< 0" or "== -1", so long as there's a >> comparison there to kick my brain out of Python boolean logic mode. > > Is there any speed difference (on common x86/64 processors and

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Terry Reedy
On 10/7/2011 10:06 AM, Nick Coghlan wrote: On Fri, Oct 7, 2011 at 9:21 AM, "Martin v. Löwis" wrote: > if (!PyUnicode_READY(foo)) is not better, also because of PyUnicode_IS_READY(foo). I prefer PyUnicode_IS_READY(foo)< 0 over PyUnicode_IS_READY(foo) == -1. Ok, so feel free to replace

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Nick Coghlan
On Fri, Oct 7, 2011 at 9:21 AM, "Martin v. Löwis" wrote: >  > if (!PyUnicode_READY(foo)) is not better, also because of >> >> PyUnicode_IS_READY(foo). >> >> I prefer PyUnicode_IS_READY(foo) < 0 over PyUnicode_IS_READY(foo) == -1. >> > > Ok, so feel free to replace all == -1 tests with < 0 tests as

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Martin v. Löwis
> if (!PyUnicode_READY(foo)) is not better, also because of PyUnicode_IS_READY(foo). I prefer PyUnicode_IS_READY(foo) < 0 over PyUnicode_IS_READY(foo) == -1. Ok, so feel free to replace all == -1 tests with < 0 tests as well. I'll point out that the test for -1 is also widespread in Python,

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Victor Stinner
Le 07/10/2011 10:07, Stefan Krah a écrit : Victor Stinner wrote: Yes, I wrote if (PyUnicode_READY(foo)), but I agree that it is confusing when you read the code, especially because we have also a PyUnicode_IS_READY(foo) macro! if (!PyUnicode_READY(foo)) is not better, also because of PyUnicode

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Stefan Krah
Victor Stinner wrote: > Yes, I wrote if (PyUnicode_READY(foo)), but I agree that it is confusing > when you read the code, especially because we have also a > PyUnicode_IS_READY(foo) macro! > > if (!PyUnicode_READY(foo)) is not better, also because of > PyUnicode_IS_READY(foo). > > I prefer

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-07 Thread Victor Stinner
Le 07/10/2011 00:20, "Martin v. Löwis" a écrit : Am 06.10.11 14:57, schrieb Amaury Forgeot d'Arc: Hi, with the new Unicode API, there are many checks like: + if (PyUnicode_READY(*filename)) + goto handle_error; I think you are misinterpreting what you are seeing. There are not *many* such che

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Greg Ewing
Benjamin Peterson wrote: Why not just have it return 0 on error? This would be more consistent with API functions that return "false" values like NULL But that would make it confusingly different from all the other functions that return ints. The NULL convention is only used when the function

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Martin v. Löwis
Am 06.10.11 14:57, schrieb Amaury Forgeot d'Arc: Hi, with the new Unicode API, there are many checks like: +if (PyUnicode_READY(*filename)) +goto handle_error; I think you are misinterpreting what you are seeing. There are not *many* such checks. Of the PyUnicode_READY chec

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Amaury Forgeot d'Arc
2011/10/6 Benjamin Peterson : > Why not just have it return 0 on error? This would be more consistent with API > functions that return "false" values like NULL and would just be > > if (!PyUnicode_READY(s)) return NULL; Most functions of the Python C API seems to follow one of two ways to indicate

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Antoine Pitrou
On Thu, 6 Oct 2011 17:40:20 -0400 Nick Coghlan wrote: > On Thu, Oct 6, 2011 at 4:47 PM, Benjamin Peterson wrote: > > Amaury Forgeot d'Arc gmail.com> writes: > > > >> I'd prefer it was written : > >>        if (PyUnicode_READY(*filename) < 0) > >> because "< 0" clearly indicates an error conditio

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Nick Coghlan
On Thu, Oct 6, 2011 at 4:47 PM, Benjamin Peterson wrote: > Amaury Forgeot d'Arc gmail.com> writes: > >> I'd prefer it was written : >>        if (PyUnicode_READY(*filename) < 0) >> because "< 0" clearly indicates an error condition. > > Why not just have it return 0 on error? This would be more c

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Benjamin Peterson
Amaury Forgeot d'Arc gmail.com> writes: > I'd prefer it was written : >if (PyUnicode_READY(*filename) < 0) > because "< 0" clearly indicates an error condition. Why not just have it return 0 on error? This would be more consistent with API functions that return "false" values like NULL a

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Nick Coghlan
On Thu, Oct 6, 2011 at 10:31 AM, Ronald Oussoren wrote: > On 6 Oct, 2011, at 14:57, Amaury Forgeot d'Arc wrote: >> I'd prefer it was written : >>       if (PyUnicode_READY(*filename) < 0) >> because "< 0" clearly indicates an error condition. >> That's how all calls to PyType_Ready are written, fo

Re: [Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Ronald Oussoren
On 6 Oct, 2011, at 14:57, Amaury Forgeot d'Arc wrote: > Hi, > > with the new Unicode API, there are many checks like: > +if (PyUnicode_READY(*filename)) > +goto handle_error; > > Every time I read it, I get it wrong: > "If filename is ready, then fail" > then I have to rem

[Python-Dev] check for PyUnicode_READY look backwards

2011-10-06 Thread Amaury Forgeot d'Arc
Hi, with the new Unicode API, there are many checks like: +if (PyUnicode_READY(*filename)) +goto handle_error; Every time I read it, I get it wrong: "If filename is ready, then fail" then I have to remember that the function returns either 0 or -1. I'd prefer it was writte