[Python-checkins] python/dist/src/Objects unicodeobject.c,2.179,2.180

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


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

Modified Files:
	unicodeobject.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: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.179
retrieving revision 2.180
diff -C2 -d -r2.179 -r2.180
*** unicodeobject.c	29 Jan 2003 17:58:45 -0000	2.179
--- unicodeobject.c	31 Jan 2003 17:19:08 -0000	2.180
***************
*** 729,735 ****
  	goto onError;
      if (newpos<0)
! 	newpos = 0;
!     else if (newpos>insize)
! 	newpos = insize;
  
      /* need more space? (at least enough for what we
--- 729,737 ----
  	goto onError;
      if (newpos<0)
! 	newpos = insize+newpos;
!     if (newpos<0 || newpos>insize) {
! 	PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", newpos);
! 	goto onError;
!     }
  
      /* need more space? (at least enough for what we
***************
*** 2247,2253 ****
      }
      if (*newpos<0)
! 	*newpos = 0;
!     else if (*newpos>size)
! 	*newpos = size;
      Py_INCREF(resunicode);
      Py_DECREF(restuple);
--- 2249,2258 ----
      }
      if (*newpos<0)
! 	*newpos = size+*newpos;
!     if (*newpos<0 || *newpos>size) {
! 	PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", *newpos);
! 	Py_DECREF(restuple);
! 	return NULL;
!     }
      Py_INCREF(resunicode);
      Py_DECREF(restuple);
***************
*** 3085,3091 ****
      }
      if (*newpos<0)
! 	*newpos = 0;
!     else if (*newpos>size)
! 	*newpos = size;
      Py_INCREF(resunicode);
      Py_DECREF(restuple);
--- 3090,3099 ----
      }
      if (*newpos<0)
! 	*newpos = size+*newpos;
!     if (*newpos<0 || *newpos>size) {
! 	PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", *newpos);
! 	Py_DECREF(restuple);
! 	return NULL;
!     }
      Py_INCREF(resunicode);
      Py_DECREF(restuple);