On 29.04.2010 21:06, Roman Yakovenko wrote:
...
First of all the error you see. In your case, py++ compiles separately
both files and then it tries to merge their declarations tree.
Obviously  it fails. I will try to find time and fix this bug.

The work around is pretty simple: create a helper file, which will
include both files and path it to py++. It should resolve this
problem.

Yes, that helped :)

Unfortunately, py++ doesn't support/generate code for boost::tuple, so
some additional work from you is needed:
...
And you should be fine.

All that worked, I was able to create python module.

I created a test and verified that the proposed solution actually
works. I will try to add "boost::tuple" support to py++ next week.

boost::tuple automatic support in py++ would be a really nice feature :)

Let me know, if you need more help with this issue.

Problem... as always when there's not enough knowledge:

I got the warning:

WARNING: boost::tuples::null_type [struct]
> execution error W1040: The declaration is unexposed, but there are other declarations, which refer to it. This could cause "no to_python converter found" run time error. Declarations: boost::tuples::tuple<JobIdWrapper::RESULT, > JobIdWrapper, std::string, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>::tuple(JobIdWrapper::RESULT > const & t0, JobIdWrapper const & t1, std::basic_string<char,std::char_traits<char>,std::allocator<char> > const & t2, boost::tuples::null_type const & t3) [constructor] boost::tuples::tuple<JobIdWrapper::RESULT, JobIdWrapper, > std::string, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>::tuple(JobIdWrapper::RESULT const & t0,

Compilation went successfully, but I can't import the module. I'm getting an error:

python: /home/macieks/boost/boost_1_42_0/libs/python/src/converter/registry.cpp:212: void boost::python::converter::registry::insert(PyObject* (*)(const void*), boost::python::type_info, const PyTypeObject* (*)()): Assertion `slot->m_to_python == 0' failed.
Aborted

To fix the warning I included boost::python::null_type:
mb.class_( 'null_type' ).include()

the warning disapeared but the module still couldn't be loaded.


Best regards
--
Maciek Sitarz
#ifndef __ALL_H__
#define __ALL_H__

#include "tuples.hpp"
#include "problem.h"

#endif // __ALL_H__
import os
import sys

from pyplusplus import module_builder

mb = module_builder.module_builder_t(
        files=['all.h'],
		include_paths=[ 
				os.getcwd()
				, "/usr/include"
				, "/usr/include/python2.4"
				, "/home/macieks/boost/boost_1_42_0"
			],
		indexing_suite_version=2
		)

mb.class_( 'JobIdWrapper' ).include()
mb.class_( 'null_type' ).include()
mb.class_( 'tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>' ).include()
mb.class_( 'map<std::string, boost::tuples::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, std::less<std::string>, std::allocator<std::pair<std::string const, boost::tuples::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >' ).include()

mb.add_registration_code( 'boost::python::register_tuple< TupleJobId >();' );

#mb.print_declarations()
mb.build_code_creator( module_name='problem' )
mb.code_creator.add_include( 'tuples.hpp' )
mb.code_creator.user_defined_directories.append( os.path.abspath('.') )
mb.write_module( os.path.join( os.path.abspath('.'), 'generated.cpp' ) )

#ifndef __TEST_H__
#define __TEST_H__

#include <map>
#include <utility>
#include <string>
#include <boost/tuple/tuple.hpp>

class JobIdWrapper {
	public:
		JobIdWrapper() : a(0) { }
		JobIdWrapper(int i) : a(i) { }
	int a;

	enum RESULT {
		OK,
		ERROR
	};

};

typedef boost::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string> TupleJobId;
typedef std::map< std::string, TupleJobId > RegisterArrayResult;

void fun( RegisterArrayResult *regArray) {
	boost::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string> tuple1(JobIdWrapper::OK, JobIdWrapper(1), "1");
	boost::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string> tuple2(JobIdWrapper::ERROR, JobIdWrapper(2), "2");

	regArray->insert(
		std::pair<std::string, boost::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string> >( "one", tuple1 )
	);
	regArray->insert(
		std::pair<std::string, boost::tuple<JobIdWrapper::RESULT, JobIdWrapper, std::string> >( "two", tuple2 )
	);

}

namespace python_problem {
	namespace details {
		inline void instantiate() {
			sizeof( JobIdWrapper );
			sizeof( RegisterArrayResult );

			JobIdWrapper c( 0 );
			RegisterArrayResult reg();
		}
	}	
}

int main( void ){
	JobIdWrapper a( 0 );
	RegisterArrayResult r();
}

#endif // __TEST_H__
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to