[C++-sig] runtime error R6025 - pure virtual function call
Maximilian Wilson
wilson.max at gmail.com
Fri Jan 26 00:18:52 CET 2007
On 1/25/07, Dave Wolfe <dwolfe at gforcetech.com> wrote:
> // File: main.cpp
> ICallable* CreatePythonHelloPrinter(std::string greetee)
> {
> ICallable* retval = NULL;
> try
> {
> bpl::object main = bpl::import("__main__");
> bpl::object global = main.attr("__dict__");
> bpl::exec_file("pyhello.py", global, global);
> bpl::object PyHelloPrinter = global["PyHelloPrinter"];
> bpl::object myPyPrinter = PyHelloPrinter(greetee);
> retval = bpl::extract<ICallable*>(myPyPrinter);
> }
> catch (bpl::error_already_set const&)
> {
> std::cerr << GetPythonException();
> }
>
> return retval;
> }
I'm no expert on bpl, but are you sure this isn't a dangling pointer?
The bpl::object myPyPrinter goes out of scope when you exit the try
block, which presumably destroys whatever ICallable retval is pointing
to. Thus, when you call pyGreeter->operator()(), you're calling a
method on an object which no longer exists and thus invoking undefined
behavior, so literally anything can happen. To solve this,
CreatePythonHelloPrinter() could return a bpl::object instead of an
ICallable*, and you'd do the extract<> call in main().
-Max Wilson
--
Be pretty if you are, be witty if you can,
But be cheerful if it kills you.
Everything in Windows is very simple, but the simplest thing is difficult.
-Clausewitz
More information about the Cplusplus-sig
mailing list