Index: Modules/zlibmodule.c =================================================================== --- Modules/zlibmodule.c (Revision 67923) +++ Modules/zlibmodule.c (Arbeitskopie) @@ -17,25 +17,15 @@ about re-entering zlib functions. N.B. - - Since ENTER_ZLIB and LEAVE_ZLIB only need to be called on functions - that modify the components of preexisting de/compress objects, it - could prove to be a performance gain on multiprocessor machines if - there was an de/compress object-specific lock. However, for the - moment the ENTER_ZLIB and LEAVE_ZLIB calls are global for ALL - de/compress objects. */ -static PyThread_type_lock zlib_lock = NULL; /* initialized on module load */ - #define ENTER_ZLIB \ Py_BEGIN_ALLOW_THREADS \ - PyThread_acquire_lock(zlib_lock, 1); \ + PyThread_acquire_lock(self->lock, 1); \ Py_END_ALLOW_THREADS #define LEAVE_ZLIB \ - PyThread_release_lock(zlib_lock); - + PyThread_release_lock(self->lock); #else #define ENTER_ZLIB @@ -67,6 +57,9 @@ PyObject *unused_data; PyObject *unconsumed_tail; int is_initialised; + #ifdef WITH_THREAD + PyThread_type_lock lock; + #endif } compobject; static void @@ -106,6 +99,9 @@ Py_DECREF(self); return NULL; } + #ifdef WITH_THREAD + self->lock = PyThread_allocate_lock(); + #endif return self; } @@ -376,23 +372,30 @@ } static void -Comp_dealloc(compobject *self) +Dealloc(compobject *self) { - if (self->is_initialised) - deflateEnd(&self->zst); + #ifdef WITH_THREAD + PyThread_free_lock(self->lock); + #endif Py_XDECREF(self->unused_data); Py_XDECREF(self->unconsumed_tail); PyObject_Del(self); } static void +Comp_dealloc(compobject *self) +{ + if (self->is_initialised) + deflateEnd(&self->zst); + Dealloc(self); +} + +static void Decomp_dealloc(compobject *self) { if (self->is_initialised) - inflateEnd(&self->zst); - Py_XDECREF(self->unused_data); - Py_XDECREF(self->unconsumed_tail); - PyObject_Del(self); + inflateEnd(&self->zst); + Dealloc(self); } PyDoc_STRVAR(comp_compress__doc__, @@ -1096,8 +1099,5 @@ PyModule_AddStringConstant(m, "__version__", "1.0"); -#ifdef WITH_THREAD - zlib_lock = PyThread_allocate_lock(); -#endif /* WITH_THREAD */ return m; }