[Python-checkins] CVS: python/dist/src/Modules zlibmodule.c,2.49,2.50
Jeremy Hylton
jhylton@users.sourceforge.net
2001年10月16日 16:26:11 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv672
Modified Files:
zlibmodule.c
Log Message:
Undo needless INCREF chicanery introduced by SF patch #450702.
Apparently this patch (rev 2.41) replaced all the good old "s#"
formats in PyArg_ParseTuple() with "S". Then it did
PyString_FromStringAndSize() to get back the values setup by the
"s#" format. It also incref'd and decref'd the string obtained by
"S" even though the argument tuple had a reference to it.
Replace PyString_AsString() calls with PyString_AS_STRING().
A good rule of thumb -- if you never check the return value of
PyString_AsString() to see if it's NULL, you ought to be using the
macro <wink>.
Index: zlibmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/zlibmodule.c,v
retrieving revision 2.49
retrieving revision 2.50
diff -C2 -d -r2.49 -r2.50
*** zlibmodule.c 2001年10月16日 23:02:32 2.49
--- zlibmodule.c 2001年10月16日 23:26:08 2.50
***************
*** 137,148 ****
int length, level=Z_DEFAULT_COMPRESSION, err;
z_stream zst;
- PyObject * inputString;
/* require Python string object, optional 'level' arg */
! if (!PyArg_ParseTuple(args, "S|i:compress", &inputString, &level))
! return NULL;
!
! /* now get a pointer to the internal string */
! if (PyString_AsStringAndSize(inputString, (char**)&input, &length) == -1)
return NULL;
--- 137,143 ----
int length, level=Z_DEFAULT_COMPRESSION, err;
z_stream zst;
/* require Python string object, optional 'level' arg */
! if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level))
return NULL;
***************
*** 159,164 ****
we clean up mallocs & INCREFs. */
- Py_INCREF(inputString); /* increment so that we hold ref */
-
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
--- 154,157 ----
***************
*** 204,208 ****
error:
free(output);
- Py_DECREF(inputString);
return ReturnVal;
--- 197,200 ----
***************
*** 223,232 ****
int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC;
z_stream zst;
- PyObject * inputString;
! if (!PyArg_ParseTuple(args, "S|ii:decompress",
! &inputString, &wsize, &r_strlen))
! return NULL;
! if (PyString_AsStringAndSize(inputString, (char**)&input, &length) == -1)
return NULL;
--- 215,221 ----
int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC;
z_stream zst;
! if (!PyArg_ParseTuple(args, "s#|ii:decompress",
! &input, &length, &wsize, &r_strlen))
return NULL;
***************
*** 240,251 ****
return NULL;
- /* Past the point of no return. From here on out, we need to make sure
- we clean up mallocs & INCREFs. */
-
- Py_INCREF(inputString); /* increment so that we hold ref */
-
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
! zst.next_out = (Byte *)PyString_AsString(result_str);
zst.next_in = (Byte *)input;
err = inflateInit2(&zst, wsize);
--- 229,235 ----
return NULL;
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
! zst.next_out = (Byte *)PyString_AS_STRING(result_str);
zst.next_in = (Byte *)input;
err = inflateInit2(&zst, wsize);
***************
*** 292,296 ****
goto error;
}
! zst.next_out = (unsigned char *)PyString_AsString(result_str) \
+ r_strlen;
zst.avail_out = r_strlen;
--- 276,280 ----
goto error;
}
! zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \
+ r_strlen;
zst.avail_out = r_strlen;
***************
*** 307,319 ****
if (err != Z_OK) {
zlib_error(zst, err, "while finishing data decompression");
! return NULL;
}
_PyString_Resize(&result_str, zst.total_out);
- Py_DECREF(inputString);
return result_str;
error:
- Py_DECREF(inputString);
Py_XDECREF(result_str);
return NULL;
--- 291,301 ----
if (err != Z_OK) {
zlib_error(zst, err, "while finishing data decompression");
! goto error;
}
_PyString_Resize(&result_str, zst.total_out);
return result_str;
error:
Py_XDECREF(result_str);
return NULL;
***************
*** 434,443 ****
Byte *input;
unsigned long start_total_out;
- PyObject *inputString;
! if (!PyArg_ParseTuple(args, "S:compress", &inputString))
! return NULL;
!
! if (PyString_AsStringAndSize(inputString, (char**)&input, &inplen) == -1)
return NULL;
--- 416,421 ----
Byte *input;
unsigned long start_total_out;
! if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen))
return NULL;
***************
*** 447,457 ****
ENTER_ZLIB
- Py_INCREF(inputString);
-
start_total_out = self->zst.total_out;
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal);
Py_BEGIN_ALLOW_THREADS
--- 425,433 ----
ENTER_ZLIB
start_total_out = self->zst.total_out;
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
***************
*** 466,470 ****
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
+ length;
self->zst.avail_out = length;
--- 442,446 ----
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ length;
self->zst.avail_out = length;
***************
*** 491,495 ****
error:
- Py_DECREF(inputString);
LEAVE_ZLIB
return RetVal;
--- 467,470 ----
***************
*** 515,521 ****
Byte *input;
unsigned long start_total_out;
- PyObject * inputString;
! if (!PyArg_ParseTuple(args, "S|i:decompress", &inputString, &max_length))
return NULL;
if (max_length < 0) {
--- 490,496 ----
Byte *input;
unsigned long start_total_out;
! if (!PyArg_ParseTuple(args, "s#|i:decompress", &input,
! &inplen, &max_length))
return NULL;
if (max_length < 0) {
***************
*** 525,531 ****
}
- if (PyString_AsStringAndSize(inputString, (char**)&input, &inplen) == -1)
- return NULL;
-
/* limit amount of data allocated to max_length */
if (max_length && length > max_length)
--- 500,503 ----
***************
*** 536,546 ****
ENTER_ZLIB
- Py_INCREF(inputString);
-
start_total_out = self->zst.total_out;
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal);
Py_BEGIN_ALLOW_THREADS
--- 508,516 ----
ENTER_ZLIB
start_total_out = self->zst.total_out;
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
***************
*** 568,572 ****
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
+ old_length;
self->zst.avail_out = length - old_length;
--- 538,542 ----
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ old_length;
self->zst.avail_out = length - old_length;
***************
*** 619,624 ****
error:
- Py_DECREF(inputString);
-
LEAVE_ZLIB
--- 589,592 ----
***************
*** 659,663 ****
self->zst.avail_in = 0;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal);
Py_BEGIN_ALLOW_THREADS
--- 627,631 ----
self->zst.avail_in = 0;
self->zst.avail_out = length;
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
***************
*** 672,676 ****
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
+ length;
self->zst.avail_out = length;
--- 640,644 ----
goto error;
}
! self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ length;
self->zst.avail_out = length;