Streams causing heap crash using Python C-Extensions
batraraj at hotmail.com
Wed Sep 17 02:04:04 CEST 2003
I've created a dll that you can import into python. The function
calls an ostringstream class. Calling this function repeatedly in python
will cause a Microsoft Visual C++ Debug Library error:
Debug Assertion Failed!
Program: C:\Program Files\Python22\python.exe
Here are snippets of the code:
// Method called by python via a PySwitchObject
static PyObject * pyCircuit(PySwitchObject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "i", &circuit))
// Error handling...
// Called by pyCircuit method above. Multiple calls to this method
// yield a heap assertion.
void Switch::circuit(U8 c)
close << "Some formating...";
// Use the close method - doesn't really matter.
The error is always within the constructor or destructor of ostringstream and
in the file called xmutex.cpp (implements mutex lock for iostreams) which
calls the malloc/dealloc functions.
I have tried other streams such as fstream, and get similar behavior.
Switching to a char buffer and sprintf is my current work around the
Any thoughts about what is going on?
I'm using Python2.2.2, with Visual C++ 7 (.NET). The error occurs using
both pythonwin and the standard command line python.
More information about the Python-list