| Store | Cart

[Python-Dev] Wg: Re: [Python-checkins] cpython (3.4): Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer

From: s.krah <ste...@bytereef.org>
Sun, 01 Mar 2015 19:45:31 +0000

 == == == == == == Weitergeleitete Nachricht == == == == == == 
Absender : Stefan Krah&lt;ste...@bytereef.org&gt;
Empfänger : "Victor Stinner"&lt;vict...@gmail.com&gt;
Datum : So, 01 Mrz 2015 18:58:43 +0000
Betreff : Re: [Python-Dev] [Python-checkins] cpython (3.4): Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
 == == == == == == Weitergeleitete Nachricht == == == == == == 

On Mon, Feb 16, 2015 at 10:14:59PM +0100, Victor Stinner wrote: 
&gt; 2015-02-16 17:34 GMT+01:00 Stefan Krah &lt;ste...@bytereef.org&gt;: 
&gt; &gt; 
&gt; &gt; On Mon, Feb 16, 2015 at 11:35:52AM +0000, serhiy.storchaka wrote: 
&gt; &gt;&gt; diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c 
&gt; &gt;&gt; --- a/Modules/_testbuffer.c 
&gt; &gt;&gt; +++ b/Modules/_testbuffer.c 
&gt; &gt;&gt; @@ -850,7 +850,7 @@ 
&gt; &gt;&gt; Py_ssize_t *dest; 
&gt; &gt;&gt; Py_ssize_t x, i; 
&gt; &gt;&gt; 
&gt; &gt;&gt; - dest = PyMem_Malloc(len * (sizeof *dest)); 
&gt; &gt;&gt; + dest = PyMem_New(Py_ssize_t, len); 
&gt; &gt;&gt; if (dest == NULL) { 
&gt; &gt;&gt; PyErr_NoMemory(); 
&gt; &gt;&gt; return NULL; 
&gt; &gt; 
&gt; &gt; This, too, was already protected by len == ndim &lt;= 64. 
&gt; 
&gt; I don't understand why you don't want to use PyMem_New() even if it 
&gt; cannot overflow. PyMem_New() is more readable no? 
 
It's readable, but I don't see a reason to change code that already has an 
overflow analysis, especially in 3.4. 
 
As I wrote in http://bugs.python.org/issue23446#msg235770 , people need to 
see that one *can* make certain assumptions about PEP-3118 buffers (otherwise 
one would go insane with overflow checks when doing arithmetic on the buffers. 
 
 
So, in a sense, this commit removes information for the reader. I would 
prefer an "assert(len &lt;= 64)" for documentation purposes while keeping the 
multiplication. 
 
 
 
Stefan Krah 
 
 





_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Stefan Krah Feb 16, 2015 04:34 pm
Victor Stinner Feb 16, 2015 09:14 pm
s.krah Mar 01, 2015 07:45 pm
Messages in this thread