Patches to for type consistency in Python pidl

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Fri Jul 17 06:05:10 UTC 2015


On 28/06/15 10:52, Jelmer Vernooij wrote:
> On Fri, Jun 26, 2015 at 09:53:21PM +1200, Douglas Bagnall wrote:
>> On 26/06/15 21:07, Jelmer Vernooij wrote:
>>> On Thu, Jun 25, 2015 at 06:20:33PM +1200, Douglas Bagnall wrote:
>>>> From 2b7e3afc390d69eebc8564c45bc1033c0ce6aca7 Mon Sep 17 00:00:00 2001
>>>> From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
>>>> Date: Thu, 18 Jun 2015 12:57:12 +1200
>>>> Subject: [PATCH 2/6] Treat uint32 as unsigned values in Pidl Python bindings
>>>>
>>>> This slightly increases memory use as uint32 now maps to Python Long
>>>> rather than Python Int. On the other hand the values have a better
>>>> chance of being consistent.
>>>>
>>>> Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
>>>
>>> -1
>>>
>>> This is hackish, and I don't see a good reason to do this. The memory usage
>>> is not a problem but this is actually changing the type we're returning.
>>> These are small integers, so they should just be regular int objects in Python.
>>>
>>> It's also special-casing uint32 and ignoring uint8, uint16.
>> It is special-casing uint32 because there are systems where uint32 won't fit in a
>> Python int. As currently implemented, I believe a uint32 greater than 1 << 31 will
>> appear in Python as a negative number on 32 bit systems. In Python the int and long 
>> types are quite interchangeable (in Python 3, they are unified and everything
>> is a long), but the values matter.
> Ah, sure. It's common practice in Python to *only* create long objects
> for values that don't fit into a plain integer object though, rather
> than creating long objects for all values. See e.g. the behaviour of
> PyInt_FromSsize_t or PytInt_FromSize_t.

Here is a version that checks the size of the value, along the lines of
those functions.

cheers,
Douglas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Treat-uint32-as-unsigned-values-in-Pidl-Python-bindi.patch
Type: text/x-diff
Size: 1862 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150717/b9f80191/0001-Treat-uint32-as-unsigned-values-in-Pidl-Python-bindi.diff>


More information about the samba-technical mailing list