[Patches] RE: Revised Patches for bug report 258 - mmapmodule.c compile pro blem

Favas, Mark (EM, Floreat) Mark.Favas@per.dem.csiro.au
Tue, 4 Apr 2000 11:07:13 +0800


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01BF9DE2.DFE78026
Content-Type: text/plain;
	charset="windows-1252"

OK - attached are revised patches based on the comments below. Compiles
without error/warning and passes test_mmap... Thanks, Greg.

Cheers,
	Mark

-----Original Message-----
From: Greg Stein [mailto:gstein@lyra.org]
Sent: Monday, 3 April 2000 6:13 PM
To: Mark Favas
Cc: patches@python.org
Subject: Re: [Patches] Patches for bug report 258 - mmapmodule.c compile
problem


On Mon, 3 Apr 2000, Mark Favas wrote:
>...
> *** mmapmodule.c.orig   Mon Apr  3 10:23:19 2000
> --- mmapmodule.c        Mon Apr  3 14:57:23 2000
> ***************
> *** 118,124 ****
>         char value;
>         char * where = (self->data+self->pos);
>         CHECK_VALID(NULL);
> !       if ((where >= 0) && (where < (self->data+self->size))) {
>                 value = (char) *(where);
>                 self->pos += 1;
>                 return Py_BuildValue("c", (char) *(where));
> --- 118,124 ----
>         char value;
>         char * where = (self->data+self->pos);
>         CHECK_VALID(NULL);
> !       if ((where >= (char *) 0) && (where < (self->data+self->size)))
> {
>                 value = (char) *(where);
>                 self->pos += 1;
>                 return Py_BuildValue("c", (char) *(where));

Nope... that should be (where >= self->data).

The more obvious test would be something like:

  if (self->pos >= 0 && self->pos < self->size)

and throw the error before ever worrying about setting up "where".

> ***************
> *** 617,623 ****
>                                 "mmap slice assignment is wrong size");
>                 return -1;
>         }
> !       buf = PyString_AsString(v);
>         memcpy(self->data + ilow, buf, ihigh-ilow);
>         return 0;
>   }
> --- 617,623 ----
>                                 "mmap slice assignment is wrong size");
>                 return -1;
>         }
> !       buf = (unsigned char *) PyString_AsString(v);
>         memcpy(self->data + ilow, buf, ihigh-ilow);
>         return 0;
>   }

Rather than casting, the definition of "buf" should change to
"const char *buf".

> ***************
> *** 640,646 ****
>                         "mmap assignment must be single-character
> string");
>                 return -1;
>         }
> !       buf = PyString_AsString(v);
>         self->data[i] = buf[0];
>         return 0;
>   }
> --- 640,646 ----
>                         "mmap assignment must be single-character
> string");
>                 return -1;
>         }
> !       buf = (unsigned char *) PyString_AsString(v);
>         self->data[i] = buf[0];
>         return 0;
>   }

Same here.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


------_=_NextPart_000_01BF9DE2.DFE78026
Content-Type: application/octet-stream;
	name="mmap-patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="mmap-patch"

*** mmapmodule.c.orig	Mon Apr  3 10:23:19 2000=0A=
--- mmapmodule.c	Tue Apr  4 10:58:26 2000=0A=
***************=0A=
*** 116,124 ****=0A=
  			   PyObject * args)=0A=
  {=0A=
  	char value;=0A=
! 	char * where =3D (self->data+self->pos);=0A=
  	CHECK_VALID(NULL);=0A=
! 	if ((where >=3D 0) && (where < (self->data+self->size))) {=0A=
  		value =3D (char) *(where);=0A=
  		self->pos +=3D 1;=0A=
  		return Py_BuildValue("c", (char) *(where));=0A=
--- 116,125 ----=0A=
  			   PyObject * args)=0A=
  {=0A=
  	char value;=0A=
! 	char * where;=0A=
  	CHECK_VALID(NULL);=0A=
! 	if (self->pos >=3D 0 && self->pos < self->size) {=0A=
! 	        where =3D self->data + self->pos;=0A=
  		value =3D (char) *(where);=0A=
  		self->pos +=3D 1;=0A=
  		return Py_BuildValue("c", (char) *(where));=0A=
***************=0A=
*** 593,599 ****=0A=
  	int ilow, ihigh;=0A=
  	PyObject *v;=0A=
  {=0A=
! 	unsigned char *buf;=0A=
  =0A=
  	CHECK_VALID(-1);=0A=
  	if (ilow < 0)=0A=
--- 594,600 ----=0A=
  	int ilow, ihigh;=0A=
  	PyObject *v;=0A=
  {=0A=
! 	const char *buf;=0A=
  =0A=
  	CHECK_VALID(-1);=0A=
  	if (ilow < 0)=0A=
***************=0A=
*** 628,634 ****=0A=
  	int i;=0A=
  	PyObject *v;=0A=
  {=0A=
! 	unsigned char *buf;=0A=
   =0A=
  	CHECK_VALID(-1);=0A=
  	if (i < 0 || i >=3D self->size) {=0A=
--- 629,635 ----=0A=
  	int i;=0A=
  	PyObject *v;=0A=
  {=0A=
! 	const char *buf;=0A=
   =0A=
  	CHECK_VALID(-1);=0A=
  	if (i < 0 || i >=3D self->size) {=0A=

------_=_NextPart_000_01BF9DE2.DFE78026--