[Python-checkins] CVS: python/dist/src/Modules mmapmodule.c,2.27,2.27.4.1

Thomas Wouters twouters@users.sourceforge.net
2001年7月12日 05:43:13 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv22342/Modules
Modified Files:
 Tag: release21-maint
	mmapmodule.c 
Log Message:
Net result of Tim's checkins 2.28 through 2.31:
- SF but #417587: compiler warnings compiling 2.1.
 Repaired *some* of the SGI compiler warnings Sjoerd Mullender
 reported.
- Minor fiddling related to
 SF patch 416251 2.1c1 mmapmodule: unused vrbl cleanup
- Fix the .find() method for memory maps.
 1) it didn't obey the "start" parameter (and when it does, we must
 validate the value)
 2) the return value needs to be an absolute index, rather than
 relative to some arbitrary point in the file
 (checking CVS, it appears this method never worked; these changes
 bring it into line with typical .find() behavior)
- Fix new compiler warnings. Also boost "start" from (C) int to long and
 return a (C) long: PyArg_ParseTuple and Py_BuildValue may not let
 us get at the size_t we really want, but C int is clearly too small
 for a 64-bit box, and both the start parameter and the return value
 should work for large mapped files even on 32-bit boxes. The code
 really needs to be rethought from scratch (not by me, though ...).
Index: mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.27
retrieving revision 2.27.4.1
diff -C2 -r2.27 -r2.27.4.1
*** mmapmodule.c	2001年01月14日 05:05:51	2.27
--- mmapmodule.c	2001年07月12日 12:43:11	2.27.4.1
***************
*** 164,177 ****
 		 PyObject *args)
 {
- 	char value;
- 	char *where;
 	CHECK_VALID(NULL);
 if (!PyArg_ParseTuple(args, ":read_byte"))
 		return NULL;
 	if (self->pos < self->size) {
! 	 where = self->data + self->pos;
! 		value = (char) *(where);
 		self->pos += 1;
! 		return Py_BuildValue("c", (char) *(where));
 	} else {
 		PyErr_SetString (PyExc_ValueError, "read byte out of range");
--- 164,174 ----
 		 PyObject *args)
 {
 	CHECK_VALID(NULL);
 if (!PyArg_ParseTuple(args, ":read_byte"))
 		return NULL;
 	if (self->pos < self->size) {
! 	 char value = self->data[self->pos];
 		self->pos += 1;
! 		return Py_BuildValue("c", value);
 	} else {
 		PyErr_SetString (PyExc_ValueError, "read byte out of range");
***************
*** 228,241 ****
 		 PyObject *args)
 {
! 	int start = self->pos;
 	char *needle;
 	int len;
 
 	CHECK_VALID(NULL);
! 	if (!PyArg_ParseTuple (args, "s#|i:find", &needle, &len, &start)) {
 		return NULL;
 	} else {
! 		char *p = self->data+self->pos;
! 		char *e = self->data+self->size;
 		while (p < e) {
 			char *s = p;
--- 225,247 ----
 		 PyObject *args)
 {
! 	long start = self->pos;
 	char *needle;
 	int len;
 
 	CHECK_VALID(NULL);
! 	if (!PyArg_ParseTuple (args, "s#|l:find", &needle, &len, &start)) {
 		return NULL;
 	} else {
! 		char *p;
! 		char *e = self->data + self->size;
! 
! if (start < 0)
! start += self->size;
! if (start < 0)
! start = 0;
! else if ((size_t)start > self->size)
! start = self->size;
! p = self->data + start;
! 
 		while (p < e) {
 			char *s = p;
***************
*** 246,251 ****
 			if (!*n) {
 				return Py_BuildValue (
! 					"i",
! 					(int) (p - (self->data + start)));
 			}
 			p++;
--- 252,257 ----
 			if (!*n) {
 				return Py_BuildValue (
! 					"l",
! 					(long) (p - self->data));
 			}
 			p++;
***************
*** 819,823 ****
 			 prot, flags,
 			 fd, 0);
! 	if (m_obj->data == (void *)-1)
 	{
 		Py_DECREF(m_obj);
--- 825,829 ----
 			 prot, flags,
 			 fd, 0);
! 	if (m_obj->data == (char *)-1)
 	{
 		Py_DECREF(m_obj);

AltStyle によって変換されたページ (->オリジナル) /