[PATCH RFC] parser: use PyInt_FromSsize_t in index_stats

Adrian Buehlmann adrian at cadifra.com
Wed May 9 16:45:27 CDT 2012


On 2012-05-09 12:37, Antoine Pitrou wrote:
> On Wed, 09 May 2012 11:06:18 +0200
> Adrian Buehlmann <adrian at cadifra.com> wrote:
>>
>> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
>> --- a/mercurial/parsers.c
>> +++ b/mercurial/parsers.c
>> @@ -506,13 +506,13 @@
>>  		return NULL;
>>  
>>  #define istat(__n, __d) \
>> -	if (PyDict_SetItemString(obj, __d, PyInt_FromLong(self->__n)) == -1) \
>> +	if (PyDict_SetItemString(obj, __d, PyInt_FromSsize_t(self->__n)) == -1) \
>>  		goto bail;
> 
> Is it common style in Mercurial not to check for errors?

Heh.

> If PyInt_FromSsize_t fails, PyDict_SetItemString called with a
> NULL value will probably segfault.
> Now the only reason I can think of for PyInt_FromSsize_t to fail is a
> MemoryError (same for PyInt_FromLong), so you might rightly argue it's
> unlikely.

I might also argue that this isn't the scope of this patch and you could
have mentioned that earlier, but that would probably be a bit too dense. :-)

In any case: TODO for a _separate_ patch. But thanks for your hint.

I also take it that you are not opposed to my approach for addressing
said warnings ("conversion from 'Py_ssize_t' to 'long', possible loss of
data").






More information about the Mercurial-devel mailing list