[Python-checkins] python/dist/src/Modules _iconv_codec.c,1.6,1.7

doerwalter@users.sourceforge.net doerwalter@users.sourceforge.net
Fri, 31 Jan 2003 09:19:40 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv3391/dist/src/Modules

Modified Files:
	_iconv_codec.c 
Log Message:
Change the treatment of positions returned by PEP293
error handers in the Unicode codecs: Negative
positions are treated as being relative to the end of
the input and out of bounds positions result in an
IndexError.

Also update the PEP and include an explanation of
this in the documentation for codecs.register_error.

Fixes a small bug in iconv_codecs: if the position
from the callback is negative *add* it to the size
instead of substracting it.

>From SF patch #677429.


Index: _iconv_codec.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_iconv_codec.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** _iconv_codec.c	31 Jan 2003 16:26:50 -0000	1.6
--- _iconv_codec.c	31 Jan 2003 17:19:07 -0000	1.7
***************
*** 248,253 ****
  
                  if (newpos < 0)
!                     newpos = inputlen - newpos;
!                 if (newpos < 0 || newpos >= inputlen)
                      break;
                  inp = inp_top + Py_UNICODE_SIZE * newpos;
--- 248,258 ----
  
                  if (newpos < 0)
!                     newpos = inputlen + newpos;
!                 if (newpos < 0 || newpos > inputlen) {
!                     PyErr_Format(PyExc_IndexError, "position %ld from error handler"
!                           " out of bounds", newpos);
!                     goto errorexit;
!                 }
!                 if (newpos == inputlen)
                      break;
                  inp = inp_top + Py_UNICODE_SIZE * newpos;
***************
*** 472,477 ****
  
                  if (newpos < 0)
!                     newpos = inplen_total - newpos;
!                 if (newpos < 0 || newpos >= inplen_total)
                      break;
                  inp = inp_top + newpos;
--- 477,487 ----
  
                  if (newpos < 0)
!                     newpos = inplen_total + newpos;
!                 if (newpos < 0 || newpos > inplen_total) {
!                     PyErr_Format(PyExc_IndexError, "position %ld from error handler"
!                           " out of bounds", newpos);
!                     goto errorexit;
!                 }
!                 if (newpos == inplen_total)
                      break;
                  inp = inp_top + newpos;