473,435 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,435 software developers and data experts.

_BLOCK_TYPE_IS_VALID error in MSVC 7.1 with Boost and Python

Hey all,

i'm trying to create an application that both embeds and extends python
through boost. i've got a rough framework up and running, but now that
i'm finally to the python part i'm having troubles.

Here's a rough run-down of my code:

Base class (pure):

template<class commandtype>
InputHandler
{
public:
/*...*/
virtual void Enter(commandtype *pOutput) = 0;
};

Derived class:
class PythonInputHandler : public InputHandler<std::string>
{
public:
PythonInputHandler(PyObject *pSelf) : m_pSelf(pSelf) {}
PythonInputHandler(const PythonInputHandler &rhs)
: InputHandler<std::string>(rhs) //doesn't really do anything
, m_pSelf(rhs.m_pSelf)
{
if(m_pSelf)
Py_XINCREF(m_pSelf);
}
virtual ~PythonInputHandler() {Py_XDECREF(m_pSelf);}

//overriden pure function:
virtual void Enter(std::string *pOutput)
{
//this is where the nasty heap crash comes in, more below
*pOutput = call_method<std::string>(m_pSelf, "Enter");
}
}

BOOST_PYTHON_MODULE(PyInputHandler)
{
class_<InputHandler<std::string>, PythonInputHandler,
boost::noncopyable>("PythonInputHandler");
}

Now, when the executable runs, this happens:
if( PyImport_AppendInittab( "PyInputHandler", initPyInputHandler ) ==
-1 )
throw runtime_error("blah");

Py_Initialize();

PyObject *pInit = PyImport_ImportModule("Python.MyTest");
if(pInit == NULL)
//...error handling

PythonInputHandler *pHandler = new
PythonInputHandler(call_method<PythonInputHandler> (pInit,
"CreateInputHandler"));

std::string sTest;
pHandler->Enter(&sTest); //big heap crash

Py_XDECREF(pInit);
/*...*/

Here is the Python code:
from PyInputHandler import *

class PyLogonHandler(PythonInputHandler):
def Enter(Output):
return "Welcome from Python!"

def CreateInitialHandler():
return PyLogonHandler()

Now then, if i change "Welcome from Python!" to a shorter string, like
"Hiya!", then it works, no error. As it stands, i get a
_BLOCK_TYPE_IS_VALID error in what looks like the destructor of the
std::string during the *pOutput = call_method... portion of the code
(i'm assuming the destructor before the assignment to pOutput occurs).
However, in the destructor, i do see the data consisting of "Welcome
from Python!"

Now i'm also a complete noob to boost and python. i've only been
working on this for about 5 hours or so (the python side of things at
any rate), so any tips to improve what i'm doing in addition to helping
with this error is greatly appreciated. i'm finding it difficult to
find some boost.python tutorials that are comprehensive enough. If you
can't tell, i'm trying to expose a version of my InputHandler class to
python so that it can be overriden and created from scripts instead of
being hard-coded into the C++.

Thanks for the help!!!!

Oct 6 '05 #1
0 1328

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
8
by: Claudio Grondi | last post by:
Here an example of what I mean (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte large file): Traceback (most recent call last): File "<pyshell#1>", line 1, in -toplevel-...
1
by: could.net | last post by:
I use boost 1.33_1, there's an example on boost::python named embedding.cpp. When I tried to build and run it in visual studio 2005, I got an error on this line: std::string hello() { return...
5
by: GaryE | last post by:
Hello: I am having trouble linking a couple of files using the boost::filesystem. I am using MSVC 6.0. Here is an abbreviated version of my problem: foo.h: #ifndef __FOO_ #define...
1
by: Lawrence Spector | last post by:
Base base; BaseWrap& baseWrap(reinterpret_cast<BaseWrap&>(base)); boost::python::object obj(boost::shared_ptr<BaseWrap>(&baseWrap)); // Compile error Results in this error: ...
0
by: Ling | last post by:
I am using boost.python to wrap C++ function which includes directmusic libraries to simply play the midi, but lots of linkage errors "error LNK2001: unresolved external symbol". I wonder if it is...
6
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be appreciated. What I'm trying to accomplish is using...
0
by: Stodge | last post by:
I'm having issues with Boost Python, downloaded via http://www.boostpro.com. I *think* it's related to WinXP side by side assemblies. My application that uses Boost Python fails to start. I ran...
3
by: ameyav | last post by:
I have migrated a c++ project from msvc 7.1 using boost 1.32 to msvc 9 using boost 1.38. I have however noticed that the binary compiled under msvc 9 is almost 25% slower than the one compiled...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.