visual C++ giving runtime heap-check error in Py_Finalize(x)
Warren Postma
embed at NOSPAM.geocities.com
Tue Jul 4 15:34:10 EDT 2000
I figured it out. I also found this nifty trick.
here it is, in case anyone else needs to track nasty malloc problems in
their Visual C++ applications, most especially useful to me while
Py_Finalize is running.
I call SetSlowButThoroughDebugOptions() before Py_Finalize, and after it, I
clear it with SetFastDebugOptions. This may turn out to be handy for
anybody writing C extensions or hacking Python internals.
Warren Postma
----- ----- ---------------------------------------- ----- -----
// setdebug.c
//
// set visual C++ runtime library heap-debug options
//
// see MSDN help topic "Using the Debug Heap from C++" and "Debug Routines"
for more help
// on the CrtSetDbgFlag and it's functions.
//
// version 0.1 warren postma
// july 4, 2000
#include <crtdbg.h> // Microsoft C Runtime Debug Options header.
#ifdef _DEBUG
void SetFastDebugOptions(void)
{
int tmpFlag;
// Get the current state of the flag
// and store it in a temporary variable
tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
// Set the new state for the flag
_CrtSetDbgFlag( tmpFlag );
}
void SetSlowButThoroughDebugOptions(void)
{
int tmpFlag;
// Get the current state of the flag
// and store it in a temporary variable
tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
// Always check at every allocation request:
tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
// Leak Check Report
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
// Set the new state for the flag
_CrtSetDbgFlag( tmpFlag );
}
#endif
----- ----- ---------------------------------------- ----- -----
More information about the Python-list
mailing list