Commit Graph

217 Commits

Author SHA1 Message Date
Andrew M. Kuchling 3b585b30c0 [Bug #1083110] calling .flush() on decompress objects causes a segfault due to an uninitialized pointer: fixes the problem and adds a test case 2004-12-28 20:10:48 +00:00
Guido van Rossum 7d9ea5013f - Thanks to Scott David Daniels, a subtle bug in how the zlib
extension implemented flush() was fixed.  Scott also rewrite the
  zlib test suite using the unittest module.  (SF bug #640230 and
  patch #678531.)

Backport candidate I think.
2003-02-03 20:45:52 +00:00
Mark Hammond 62b1ab1b31 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
command line for Windows builds.  This should allow MSVC to import and
build the Python MSVC6 project files without error.
2002-07-23 06:31:15 +00:00
Tim Peters 0c32279626 Removed more stray instances of statichere, but left _sre.c alone. 2002-07-17 16:49:03 +00:00
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Tim Peters 5de9842b34 Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs.  The
most common usage error is of this form (often spread out across gotos):

	if (_PyString_Resize(&s, n) < 0) {
		Py_DECREF(s);
		s = NULL;
		goto outtahere;
	}

The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL.  So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s):  s is already
NULL!  A correct way to write the above is the simpler (and intended)

	if (_PyString_Resize(&s, n) < 0)
		goto outtahere;

Bugfix candidate.
2002-04-27 18:44:32 +00:00
Jeremy Hylton c72737e7b6 Fix SF #544995 (zlib crash on second flush call)
Bug fix by mhammond.

Bug fix candidate for 2.2, not present in 2.1.
2002-04-19 14:37:07 +00:00
Fred Drake 4baedc1d9b Use the PyModule_Add*() APIs instead of manipulating the module dict
directly.
2002-04-01 14:53:37 +00:00
Sjoerd Mullender 556a938d10 Changed C++ comment into standard comment. 2002-03-11 09:20:47 +00:00
Guido van Rossum 146483964e Patch supplied by Burton Radons for his own SF bug #487390: Modifying
type.__module__ behavior.

This adds the module name and a dot in front of the type name in every
type object initializer, except for built-in types (and those that
already had this).  Note that it touches lots of Mac modules -- I have
no way to test these but the changes look right.  Apologies if they're
not.  This also touches the weakref docs, which contains a sample type
object initializer.  It also touches the mmap test output, because the
mmap type's repr is included in that output.  It touches object.h to
put the correct description in a comment.
2001-12-08 18:02:58 +00:00
Jack Jansen 72af01aac6 Added missing cast. 2001-10-23 22:29:06 +00:00
Jeremy Hylton 771f9146d5 Remove unused convenience routine. 2001-10-17 13:32:02 +00:00
Tim Peters adbd35bbcc Simplify and regularize docstrings. Also reformat so that each docstring
line fits in reasonable screen width.
2001-10-17 04:16:15 +00:00
Tim Peters 977e540e4b Trimmed trailing whitespace. 2001-10-17 03:57:20 +00:00
Tim Peters b1a37c0196 Removed more comments that didn't make much sense.
Made the presence/absence of a semicolon after macros consistent.
2001-10-17 03:56:45 +00:00
Tim Peters 6605c64c83 Removed obsolete comments about confused string refcount tricks (Jeremy
removed the tricks).

Changed the ENTER/LEAVE_ZLIB macros so as not to create a new block (a
new block is neither necessary nor helpful).
2001-10-17 03:43:54 +00:00
Jeremy Hylton ba3dd9990f 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>.
2001-10-16 23:26:08 +00:00
Jeremy Hylton 9d620d018c Simplify and fix error handling for most cases.
Many functions used a local variable called return_error, which was
initialized to zero.  If an error occurred, it was set to true.  Most
of the code paths checked were only executed if return_error was
false.  goto is clearer.

The code also seemed to be written under the curious assumption that
calling Py_DECREF() on a local variable would assign the variable to
NULL.  As a result, more of the error-exit code paths returned an
object that had a reference count of zero instead of just returning
NULL.  Fixed the code to explicitly assign NULL after the DECREF.

A bit more reformatting, but not much.

XXX Need a much better test suite for zlib, since it the current tests
don't exercise any of this broken code.
2001-10-16 23:02:32 +00:00
Jeremy Hylton 4990000077 More reformatting. 2001-10-16 21:59:35 +00:00
Jeremy Hylton 0965e084cd Add zlib_error() helper.
It sets a ZlibError exception, using the msg from the z_stream pointer
if one is available.
2001-10-16 21:56:09 +00:00
Jeremy Hylton 9bc9d66eb1 Remove many calls to set MemoryError exceptions.
When PyString_FromStringAndSize() and _PyString_Resize() fail, they
set an exception.  There's no need to set a new exception.
2001-10-16 21:23:58 +00:00
Jeremy Hylton 9714f99d60 Reformat!
Consistently indent 4 spaces.
Use whitespace around operators.
Put braces in the right places.
2001-10-16 21:19:45 +00:00
Jeremy Hylton 511e2cacc4 [ #403753 ] zlib decompress; uncontrollable memory usage
Mostly by Toby Dickenson and Titus Brown.

Add an optional argument to a decompression object's decompress()
method.  The argument specifies the maximum length of the return
value.  If the uncompressed data exceeds this length, the excess data
is stored as the unconsumed_tail attribute.  (Not to be confused with
unused_data, which is a separate issue.)

Difference from SF patch: Default value for unconsumed_tail is ""
rather than None.  It's simpler if the attribute is always a string.
2001-10-16 20:39:49 +00:00
Martin v. Löwis 1dbce44b91 Update URL. Fixes bug #468118. 2001-10-09 10:54:31 +00:00
Martin v. Löwis caef93d82c Silence warnings about passing unsigned char** as char**. 2001-09-08 16:23:34 +00:00
Martin v. Löwis 3bd8c1ee47 Patch #450702: allow threads when calling into zlib, protect usage of
the module in multiple threads with a global lock.
2001-09-07 16:27:31 +00:00
Andrew M. Kuchling a1a690fa9c Patch #103926: fix two warnings from Tru64's compiler 2001-02-22 15:52:55 +00:00
Andrew M. Kuchling 9aff4a2ad0 Patch #103373 from Donovan Baarda: This patch:
* fixes the zlib decompress sync flush bug as reported in bug #124981
  * avoids repeat calls to (in|de)flateEnd when destroying (de)compression
    objects
  * raises exception when allocating unused_data fails
  * fixes memory leak when allocating unused_data fails
  * raises exception when allocating decompress data fails
  * removes vestigial code from decompress flush now that decompression
    returns all available data
  * tidies code so object compress/decompress/flush routines are consistent
2001-02-21 02:15:56 +00:00
Tim Peters ee826f88c9 Docs for new Windows zlib build procedure. 2001-01-31 19:39:44 +00:00
Mark Hammond ae8c268a2b Fix [ Bug #129293 ] zlib library used for binary win32 distribution can crash
This involves changing the zlib build process to build zlib itself from sources, then use that library.  Also updated are the comments to reflect the new official home of zlib, and add Windows specific notes regarding the build process.
2001-01-31 10:28:03 +00:00
Andrew M. Kuchling d923831027 Patch #101810: check whether zst.avail_out is non-zero when getting
a Z_BUF_ERROR while decompressing.  If it is, assume that this means
   the data being decompressed is bad and raise an exception, instead of
   just assuming that Z_BUF_ERROR always means that more space is required.
2000-10-09 14:18:10 +00:00
Andrew M. Kuchling 14f515844d Use METH_VARARGS instead of numeric constant 1 2000-08-03 02:04:05 +00:00
Thomas Wouters f3f33dcf03 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
and a couple of functions that were missed in the previous batches. Not
terribly tested, but very carefully scrutinized, three times.

All these were found by the little findkrc.py that I posted to python-dev,
which means there might be more lurking. Cases such as this:

long
func(a, b)
	long a;
	long b; /* flagword */
{

and other cases where the last ; in the argument list isn't followed by a
newline and an opening curly bracket. Regexps to catch all are welcome, of
course ;)
2000-07-21 06:00:07 +00:00
Peter Schneider-Kamp a788a7f0fb ANSI-fication 2000-07-10 09:57:19 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Guido van Rossum 54b1c0b408 Windows: Since we're not using ZLIB.DLL any more, don't define ZLIB_DLL.
(Mark Hammond.)
2000-04-06 13:20:38 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Fred Drake 8972dfd58e For ZlibError and ZLIB_VERSION, only attempt to add entry to the
module dict if the inserted object isn't NULL (basic defensive
programming!).
1999-12-22 16:13:54 +00:00
Andrew M. Kuchling 313a3e36e7 Fix typo in docstring: wbites -> wbits 1999-12-20 22:13:38 +00:00
Guido van Rossum aee9bb2d0b Cast added by Jack Jansen (for Mac port). 1999-04-12 14:35:48 +00:00
Guido van Rossum b729a1d0a8 Patch by Andrew Kuchling to unflush() (flush() for deflating).
Without this, if inflate() returned Z_BUF_ERROR asking for more output
space, we would report the error; now, we increase the buffer size and
try again, just as for Z_OK.
1999-04-07 20:23:17 +00:00
Andrew M. Kuchling b95227db4f Add an .unused_data attribute to decompressor objects. If .unused_data
is not an empty string, this means that you have arrived at the
end of the stream of compressed data, and the contents of .unused_data are
whatever follows the compressed stream.
1999-03-25 21:21:08 +00:00
Andrew M. Kuchling 173156fa32 Fixed the flush() method of compression objects; the test for
the end of loop was incorrect, and failed when the flushmode != Z_FINISH.
    Logic cleaned up and commented.
1999-03-22 19:25:30 +00:00
Andrew M. Kuchling 1c7aaa2d73 Added missing DECREF's in the error branches when creating a compressor or
decompressor object.  This required adding a flag to the struct which is
    true if initialisation was completed; on object destruction, deflateEnd()
    is only called if the flag is true.
1999-01-29 21:49:34 +00:00
Barry Warsaw 30aa1e7d31 PyInit_zlib(): Plug a small memory leak. Jeremy is looking into the
more severe ones.
1999-01-28 19:40:05 +00:00
Jeremy Hylton 6892aa372d fix bug in PyZlib_flush.
patch from Grzegorz Makarewicz & Rafal Smotrzyk.
1999-01-06 22:56:24 +00:00
Jeremy Hylton 5bc4abe006 replace missing zalloc initialization (test_zlib now runs
successfully)
1998-12-21 17:15:00 +00:00
Jeremy Hylton 36252022ec remove debugging fprintf (should have checked this before previous
checkin)
1998-12-21 16:40:21 +00:00
Jeremy Hylton a37e244536 patches from Andrew
NOTE: There is still a bug of some sort in the behavior of zlib.  In
at least one case, inflate returns Z_OK (which is typically
interpreted to mean that more output space is needed) when it has
finished inflating a buffer.  This has been reported as a bug to the
zlib maintainers; we may need to change the Python interface.
1998-12-18 22:13:11 +00:00
Fred Drake 6de7d0c338 When _PyString_Resize() reports failure, the variable referring to the
string we wanted to resize is set to NULL.  Don't Py_DECREF() those
variables!  (5 places)
1998-12-18 19:46:59 +00:00
Guido van Rossum 3886bb6997 Add DL_EXPORT() to all modules that could possibly be used
on BeOS or Windows.
1998-12-04 18:50:17 +00:00
Guido van Rossum c69bac539c Fix benign problems found by a picky SGI compiler (unreachable break
after a return).
1998-07-07 22:21:45 +00:00
Guido van Rossum 821a5e42bf Added URLs for zlib's home page and the Windows DLL's home page . 1998-05-08 14:56:29 +00:00
Guido van Rossum 115f517f77 Tiny patch for zlib 1.1.2 1998-04-23 20:22:11 +00:00
Guido van Rossum 9ec0f8b405 Win32 treatment. 1997-12-18 05:21:29 +00:00
Guido van Rossum 0cb96de269 Apply two changes, systematically:
(1) Use PyErr_NewException("module.class", NULL, NULL) to create the
    exception object.

(2) Remove all calls to Py_FatalError(); instead, return or
    ignore the errors -- the import code now checks PyErr_Occurred()
    after calling a module's init function, so it's no longer a
    fatal error for the initialization to fail.

Also did some small cleanups, e.g. removed unnecessary test for
"already initialized" from initfpectl(), and unified
initposix()/initnt().

I haven't checked this very thoroughly, so while the changes are
pretty trivial -- beware of untested code!
1997-10-01 04:29:29 +00:00
Jeremy Hylton cb91404890 Several changes:
1. Fix bug in (de)compression objects.  The final string resize used
zst.total_out to determine the length of the string, but the
(de)compression object will output data a little bit at a time, which
means total_out is not the string size.  Fix: save original value of
total_out at the start of the call.

2. Be sure to Py_DECREF the result value if you exit with an
exception.

3. Use PyInt_FromLong instead of Py_BuildValue

4. include more constants from the zlib header file

5. Use PyErr_Format instead of using a local buffer and sprintf.
1997-09-04 23:39:23 +00:00
Guido van Rossum c3beda2f27 Plug small leaks: the [de]compress object itself was never freed. 1997-09-03 18:14:30 +00:00
Guido van Rossum c1f088201f Added (binaryfunc) casts to function pointers in method lists. 1997-08-28 21:21:22 +00:00
Guido van Rossum ed2554a396 Casts by Jack to shut up the Mac compiler. 1997-08-18 15:31:24 +00:00
Jeremy Hylton 644c17d2af Several bug fixes.
-- initialize length to DEFAULTALLOC and not 0
 -- resize string before returning (to remove '\000' padding)

Also converted some compression routines to use PyString instead of
buffer.
1997-08-14 21:06:42 +00:00
Jeremy Hylton 41b9f00e8f Many changes.
Change default alloc size for uncompressing to 16K.

Remove comment about core dumps when an invalid window sizes is used.
This bug has been fixed in zlib 1.0.4.

Two new optional arguments to decompress, wbits and bufsize.  wbits
specifies the window size and bufsize specifies the initial output
string size.

In decompression code -- decompress and decompressobj methods -- use a
Python string (and _PyString_Resize) to collect the uncompressed
stream.  Replaces a separate buffer that was copied into a string.

Fix bug in decompress that caused it to always realloc the buffer when
it was finished decompressing.

Modernized handling of optional arguments to compressobj.

Updated doc strings.
1997-08-13 23:19:55 +00:00
Jeremy Hylton a74ef66ac8 Must update the available space in the output buffer after
realloc. (Fixed in PyZlib_unflush.)
1997-08-13 21:39:18 +00:00
Guido van Rossum 97b5457467 Small changes (casts etc.) by Jack, for Mac compilation. 1997-06-03 22:21:47 +00:00
Guido van Rossum 3c540307af Doc strings (AMK). 1997-06-03 22:21:03 +00:00
Guido van Rossum fb221562a3 Added Andrew Kuchling's zlib module. 1997-04-29 15:38:09 +00:00