Hmm.. I can't really recompile my code with the /Zc:wchar_t directive, and I would much rather not deal with writing wrapper code the convert the regular python str into our str type (my manager is hesitant about copying strings around for conversion purpose as he thinks it will be performance sapping).
What about rebuilding boost so that /Zc:wchar_t is set to NO? Would this be a workable thing?
Again, thanks for your help.
J.Lu
-----Original Message-----
From: pyg...@li... [mailto:pyg...@li...] On Behalf Of Roman Yakovenko
Sent: Monday, April 07, 2008 9:32 AM
To: pygccxml mailing list
Subject: [pygccxml-development] Fwd: [pygccxml-commit] string type mismatchbetween python and C++
---------- Forwarded message ----------
From: Roman Yakovenko <rom...@gm...>
Date: Mon, Apr 7, 2008 at 4:31 PM
Subject: Re: [pygccxml-commit] string type mismatch between python and C++
To: Johnson Lu <joh...@op...>
On Mon, Apr 7, 2008 at 9:55 AM, Johnson Lu <joh...@op...> wrote:
> Hello Mr. Yakovenko:
Roman is just fine :-)
> The compiler I am using is VC 7.1, and we also use the openTop
> libraries.
>
> I am wrapping a class that is part of a large multi-platform product,
> and in our product we have some fairly convoluted header includes that,
> I think, make strings into different types base on the platform being
> compiled on. On VC7.1 simple string became unsigned shorts (heaven only
> knows).
>
> Here is a simple snippet of that function as generated by PY++:
>
> struct ClassificationOutput_wrapper : ClassificationOutput, bp::wrapper<
> ClassificationOutput > {
> .
> .
> .
> virtual void setApplicationName( ::ot::String const &
> applicationName ) {
> if( bp::override func_setApplicationName = this->get_override(
> "setApplicationName" ) )
> func_setApplicationName( applicationName );
> else
> this->ClassificationOutput::setApplicationName(
> applicationName );
> }
> void default_setApplicationName( ::ot::String const &
> applicationName ) {
> ClassificationOutput::setApplicationName( applicationName );
> }
> .
> .
> .
> }
> BOOST_PYTHON_MODULE(pyplusplus){
> bp::class_< ClassificationOutput_wrapper, boost::noncopyable >(
> "ClassificationOutput" )
> .def( bp::init< >() )
> .
> .
> .
> .def(
> "setApplicationName"
> , &::ClassificationOutput::setApplicationName
> , &ClassificationOutput_wrapper::default_setApplicationName
> , ( bp::arg("applicationName") ) )
>
>
> And here is the original .h snippet for the function...
>
> class ClassificationBuiltinImplDeclSpec ClassificationOutput : public
> IClassificationModifiableOutput
> {
> .
> .
> .
> virtual void setApplicationName(const String& applicationName) ;
>
> And my test code simply creates a C++ ClassificationOutput object:
>
> ClassificationOutput mm;
> mm.setApplicationName(OPTIER_T("monty python"));
> mm.setUserName(OPTIER_T("jclu"));
> .
> .
> .
> bpl::object pyCls(boost::ref(mm));
> main_namespace["output"] = pyCls;
>
> Pass it to Python via name space addition to the python dictionary, then
> used a simple python code:
> output.setApplicationName("anApplication") # and this line does
> not work.
> output.getUserName() # returns jclu, so python can read from
> C++
>
> All seem very straight forward, except not quite so, for me.
>
> Again, really appreciate your help.
Okey, I think I understand the problem and was able to reproduce it.
Solution:
1. http://boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#custom_string
2. http://language-binding.net/pyplusplus/documentation/inserting_code.html#insert-code-to-module
Explanation: I guess Boost.Python was compiled with "Yes
(/Zc:wchar_t)" option turned on. Thus class std::basic_string<
unsigned short > and std::basic_string< wchar_t > are 2 different
classes. So you will have to define your own string conversion or
recompile all your source code with the option.
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
pygccxml-development mailing list
pyg...@li...
https://lists.sourceforge.net/lists/listinfo/pygccxml-development
|