Commit 63f6202e authored by Jim Fulton's avatar Jim Fulton

Put limit on number of cached wrapper objects to prevent wrapper leakage.

parent 83a58eff
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: Acquisition.c,v 1.31 1999/08/05 21:36:50 jim Exp $ $Id: Acquisition.c,v 1.32 1999/09/21 22:33:44 jim Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -135,8 +135,6 @@ typedef struct { ...@@ -135,8 +135,6 @@ typedef struct {
PyObject *container; PyObject *container;
} Wrapper; } Wrapper;
static Wrapper *freeWrappers=0;
staticforward PyExtensionClass Wrappertype, XaqWrappertype; staticforward PyExtensionClass Wrappertype, XaqWrappertype;
#define isWrapper(O) ((O)->ob_type==(PyTypeObject*)&Wrappertype || \ #define isWrapper(O) ((O)->ob_type==(PyTypeObject*)&Wrappertype || \
...@@ -178,6 +176,10 @@ err: ...@@ -178,6 +176,10 @@ err:
return NULL; return NULL;
} }
static Wrapper *freeWrappers=0;
static int nWrappers=0;
#define MAX_CACHED_WRAPPERS 200
static PyObject * static PyObject *
newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype) newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype)
{ {
...@@ -189,6 +191,7 @@ newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype) ...@@ -189,6 +191,7 @@ newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype)
freeWrappers=(Wrapper*)self->obj; freeWrappers=(Wrapper*)self->obj;
self->ob_type=Wrappertype; self->ob_type=Wrappertype;
self->ob_refcnt=1; self->ob_refcnt=1;
nWrappers--;
} }
else else
UNLESS(self = PyObject_NEW(Wrapper, Wrappertype)) return NULL; UNLESS(self = PyObject_NEW(Wrapper, Wrappertype)) return NULL;
...@@ -206,8 +209,17 @@ Wrapper_dealloc(Wrapper *self) ...@@ -206,8 +209,17 @@ Wrapper_dealloc(Wrapper *self)
{ {
Py_DECREF(self->obj); Py_DECREF(self->obj);
Py_DECREF(self->container); Py_DECREF(self->container);
self->obj=OBJECT(freeWrappers); if (nWrappers < MAX_CACHED_WRAPPERS)
freeWrappers=self; {
self->obj=OBJECT(freeWrappers);
freeWrappers=self;
nWrappers++;
}
else
{
Py_DECREF(self->ob_type);
PyMem_DEL(self);
}
} }
static PyObject * static PyObject *
...@@ -1000,7 +1012,7 @@ void ...@@ -1000,7 +1012,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.31 $"; char *rev="$Revision: 1.32 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -1019,7 +1031,7 @@ initAcquisition() ...@@ -1019,7 +1031,7 @@ initAcquisition()
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.31 1999/08/05 21:36:50 jim Exp $\n", "$Id: Acquisition.c,v 1.32 1999/09/21 22:33:44 jim Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: Acquisition.c,v 1.31 1999/08/05 21:36:50 jim Exp $ $Id: Acquisition.c,v 1.32 1999/09/21 22:33:44 jim Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -135,8 +135,6 @@ typedef struct { ...@@ -135,8 +135,6 @@ typedef struct {
PyObject *container; PyObject *container;
} Wrapper; } Wrapper;
static Wrapper *freeWrappers=0;
staticforward PyExtensionClass Wrappertype, XaqWrappertype; staticforward PyExtensionClass Wrappertype, XaqWrappertype;
#define isWrapper(O) ((O)->ob_type==(PyTypeObject*)&Wrappertype || \ #define isWrapper(O) ((O)->ob_type==(PyTypeObject*)&Wrappertype || \
...@@ -178,6 +176,10 @@ err: ...@@ -178,6 +176,10 @@ err:
return NULL; return NULL;
} }
static Wrapper *freeWrappers=0;
static int nWrappers=0;
#define MAX_CACHED_WRAPPERS 200
static PyObject * static PyObject *
newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype) newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype)
{ {
...@@ -189,6 +191,7 @@ newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype) ...@@ -189,6 +191,7 @@ newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype)
freeWrappers=(Wrapper*)self->obj; freeWrappers=(Wrapper*)self->obj;
self->ob_type=Wrappertype; self->ob_type=Wrappertype;
self->ob_refcnt=1; self->ob_refcnt=1;
nWrappers--;
} }
else else
UNLESS(self = PyObject_NEW(Wrapper, Wrappertype)) return NULL; UNLESS(self = PyObject_NEW(Wrapper, Wrappertype)) return NULL;
...@@ -206,8 +209,17 @@ Wrapper_dealloc(Wrapper *self) ...@@ -206,8 +209,17 @@ Wrapper_dealloc(Wrapper *self)
{ {
Py_DECREF(self->obj); Py_DECREF(self->obj);
Py_DECREF(self->container); Py_DECREF(self->container);
self->obj=OBJECT(freeWrappers); if (nWrappers < MAX_CACHED_WRAPPERS)
freeWrappers=self; {
self->obj=OBJECT(freeWrappers);
freeWrappers=self;
nWrappers++;
}
else
{
Py_DECREF(self->ob_type);
PyMem_DEL(self);
}
} }
static PyObject * static PyObject *
...@@ -1000,7 +1012,7 @@ void ...@@ -1000,7 +1012,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.31 $"; char *rev="$Revision: 1.32 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -1019,7 +1031,7 @@ initAcquisition() ...@@ -1019,7 +1031,7 @@ initAcquisition()
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.31 1999/08/05 21:36:50 jim Exp $\n", "$Id: Acquisition.c,v 1.32 1999/09/21 22:33:44 jim Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment