[issue20341] Argument Clinic: add "nullable ints"

Larry Hastings report at bugs.python.org
Wed Jan 22 22:05:15 CET 2014


Larry Hastings added the comment:

> int(or_none=True) ?

Yes, that is a different name that seems to mean much the same thing.


> Hmm, do we have a getargs.h ?

No.  Would it help if I attached the output of "ls Include"
to this issue?


> > > - boolean fields can be "char" instead of "int" (and moved at the
> > >   end to pack the structure more efficiently)
> > 
> > Is Python really compiled with packed structures?
> 
> You don't understand me. If you write:
>   struct X { int A; char B; char C; }
> the structure will be packed *by definition* (IIRC).

I understand you fine.  That's not guaranteed by the C standard,
and I've used compilers that didn't pack structures by default.
More to the point, unaligned accesses on Intel are more expensive
than aligned accesses, and on other architectures I've written
C code using packed structures with unaligned accesses that
produced a bus error.

http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding

And finally: I removed "error"--you were right, it was unnecessary
for the nullable ints.  So now it's just

  { int error; <whatever> i; }

Changing error to an char and moving it to the end would
save exactly zero bytes, because the compiler *will* align
stack variables to 4 byte boundaries.  I can give you a sample
C program if you want proof.


> > > - PyLong_AsSsize_t can't fail?
> > Not on an object returned by PyNumber_Index().
> And what if the long is too long to fit in a Py_ssize_t?

Ah.  I thought PyNumber_Index guaranteed it would fit, but
I was mistaken.  Code is fixed.


New patch posted.  I believe this fixes all the bugs cited so far.


Also, I don't know what the right thing to do about itertools.repeat
is.  The current signature is a bug, it should not behave differently
between repeat(o, -1) and repeat(o, times=-1).  If we go by the
documentation, repeat(o, None) and repeat(o, times=None) are what we
want.  But I bet code out there relies on repeat(o, times=-1), so we
may be stuck supporting that.  You should consider my signature for
itertools.repeat in these "draft" patches as a proof of concept, not
as code that should be checked in.

The issue is being discussed on #19145.

----------
Added file: http://bugs.python.org/file33635/larry.nullable.ints.draft.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20341>
_______________________________________


More information about the Python-bugs-list mailing list