[C++-sig] Cannot believe what my eyes see: ACCES VIOLATION...

yakumoklesk at yahoo.es yakumoklesk at yahoo.es
Sun Sep 14 16:09:28 CEST 2003


This is the program that causes the acces violation. Can't be more simple...

#include <python.h>
#include <boost/python.hpp>

namespace python = boost::python;

void func()
{
	python::handle<> main_module( python::borrowed( PyImport_AddModule( 
"__main__" ) ) );
	//python::handle<> main_namespace( python::borrowed( PyModule_GetDict( 
main_module.get() ) ) );
	PyRun_SimpleString("a = 3");
	
	python::handle<> hmain_namespace( python::borrowed( 
PyModule_GetDict(main_module.get() ) ) );
	python::dict main_namespace( hmain_namespace );
}

int main( int argc, char** argv )
{
	Py_Initialize();
	func();
	Py_Finalize();

	return 0;
}

The acces violation occurs in the last line of the func() code:

python::dict main_namespace( hmain_namespace );

I have been trying to debug what happens. This is what I have got. Don't know if it will 
be useful:

In the template function

template <class T>
    explicit dict(T const& data)
        : base(object(data))
    {
    }

data, in this case, the handle<> named main_namespace, holds the following 
information

-	data	{...}
-	m_p	0x00ae33b0
+	_ob_next	0x00ae3338
+	_ob_prev	0x00ae3478
	ob_refcnt	2
+	ob_type	0x00574038 _PyDict_Type

inside the function object

object::object(handle<> const& x)
     : object_base(python::incref(python::expect_non_null(x.get())))
{}

x should have the same information as data had before, because is the same handle<>, 
but I find the following:

-	x	{...}
-	m_p	0x00ae33b0
	ob_refcnt	11416376
+	ob_type	0x00ae3478

It seems that the PyObject structure pointed by m_p has... dynamically changed? Well, 
sorry if I am sayin nonsenses, but I don't know what to do. Maybe it would be better for 
me to use objects and only use handles, but then there is no sense in using boost, 
because I could only get the advantage PyObject handling.

More details of my project:

It is a windows 32 console application, made in Visual C++ 6.0
I am using the directives _DEBUG, and the boost_python_debug.lib library that this 
morning compiled using bjam and the source code that checked out from boost-
consulting.com yesterday at night.
The version of the puthon libraries is 2.2.3, but it fails also with 2.2.1.

The include path of the proyect is:

E:\proxp\prog\DirectX 9.0 SDK\Lib
E:\PROXP\PROG\DIRECTX 8.1 SDK VC++\INCLUDE
e:\proxp\prog\VC++ 6.0\INCLUDE
e:\proxp\prog\VC++ 6.0\ATL\INCLUDE
e:\proxp\prog\VC++ 6.0\MFC\INCLUDE
E:\PROXP\PROG\PYTHON 2.2.1\INCLUDE (when i tried with 2.2.3 i changed it to 2.2.3 
of course)
E:\proxp\prog\boost checkout-14-09-2003 boost-consulting.com

The library path of the proyect is:

E:\proxp\prog\DirectX 9.0 SDK\Lib
E:\PROXP\PROG\DIRECTX 8.1 SDK VC++\LIB
e:\proxp\prog\VC++ 6.0\LIB
e:\proxp\prog\VC++ 6.0\MFC\LIB
E:\proxp\prog\Python 2.2.1 source\PCbuild (because I use python_d.dll for debug 
version. As above, i change to 2.2.3 when i using 2.2.3 includes)
E:\proxp\prog\boost checkout-14-09-2003 boost-consulting.com\libs\python\build\bin-
stage ( I have also tried E:\proxp\prog\boost checkout-14-09-2003 boost-
consulting.com\libs\python\build\bin\boost_python.dll\msvc\debug\runtime-link-dynamic 
with the same ACCES VIOLATION result )

I also have tried to compile the boost.python libraries using msvc with the project 
located in E:\proxp\prog\boost checkout-14-09-2003 boost-
consulting.com\libs\python\build\VisualStudio
but I get tons of erros from the

e:\proxp\prog\VC++ 6.0\INCLUDE\mmreg.h file, saying things lik

'WORD' : missing storage-class or type specifiers

and other types as well that VC does not find.

This seems strange to me, that a file from VC++ include has this kind of errors.

Any hint would be appreciate. If need more details, just ask me.

David Lucena









More information about the Cplusplus-sig mailing list