Hi, Say I have a C++ class exposed to python. The C++ code creates an instance of said class and I want to retrieve it from python code. What would be the correct way for python code to 'get' the reference? Regardless can someone please elaborate on the the whole "param passing & return value" subject. It might be me but I had a hard time with return_arg<> (I don't get what arg_pos is suppose to mean), and the example discusses only return_self What I *tried* to do is: MyClass* pMyClass; main() { pMyClass = new MyClass; } MyClass* GetMyClass() { return pMyClass; } BOOST_PYTHON_MODULE(mymod) { class_<MyClass>..... def ("GetMyClass", GetMyClass); } This didn't compile with "C2027 use of unspecified type boost::python::detail::specify_a_return_value_to_wrap_functions_returning<T> with T=result_t". I tried messing around with the def, adding return_arg<> but nothing did the trick for me. Cheers, Ira
"Ira" <sheig222@gmail.com> writes:
What I *tried* to do is:
MyClass* pMyClass;
main() { pMyClass = new MyClass; }
MyClass* GetMyClass() { return pMyClass; }
BOOST_PYTHON_MODULE(mymod) { class_<MyClass>.....
def ("GetMyClass", GetMyClass); }
This didn't compile with "C2027 use of unspecified type boost::python::detail::specify_a_return_value_to_wrap_functions_returning<T> with T=result_t".
You need to specify a return value policy when returning pointers and references from functions, because otherwise Boost.Python doesn't know how/whether to manage the lifetime of the thing referred to. In this case, reference_existing_object looks like the right policy. Since GetMyClass has no arguments, return_arg certainly can't be the right choice! HTH, Dave P.S. Next time I suggest you copy/paste your actual code and the actual error message. It was specify_a_return_value_policy_to_wrap_functions_returning ^^^^^^^ -- Dave Abrahams Boost Consulting www.boost-consulting.com
You need to specify a return value policy when returning pointers and references from functions, because otherwise Boost.Python doesn't know how/whether to manage the lifetime of the thing referred to. In this case, reference_existing_object looks like the right policy. Since GetMyClass has no arguments, return_arg certainly can't be the right choice!
Can you please point me to where I can find an in-depth discussion of return value policies? Are the 6 models under boost::python docs' ConverterGenerator all I can use/need?
P.S. Next time I suggest you copy/paste your actual code and the actual error message. It was specify_a_return_value_policy_to_wrap_functions_returning
Lol, sorry about that. The secret police here at where I work restrict us from doing *very dangerous* stuff like downloading MP3's, zip files with source code in them, installing winamp... Ohh and also posting to newsgroups. I have to use a different 'dirty' workstation to post here so I can't simply copy/paste. I'll make an effort to be more accurate in the future. Cheers, Ira
"Ira Holtzer" <sheig222@gmail.com> writes:
You need to specify a return value policy when returning pointers and references from functions, because otherwise Boost.Python doesn't know how/whether to manage the lifetime of the thing referred to. In this case, reference_existing_object looks like the right policy. Since GetMyClass has no arguments, return_arg certainly can't be the right choice!
Can you please point me to where I can find an in-depth discussion of return value policies?
http://www.boost.org/libs/python/doc/v2/ResultConverter.html#ResultConverter...
Are the 6 models under boost::python docs' ConverterGenerator all I can use/need?
You can write your own as long as it conforms to the requirements for ResultConverterGenerator.
P.S. Next time I suggest you copy/paste your actual code and the actual error message. It was specify_a_return_value_policy_to_wrap_functions_returning
Lol, sorry about that. The secret police here at where I work restrict us from doing *very dangerous* stuff like downloading MP3's, zip files with source code in them, installing winamp... Ohh and also posting to newsgroups. I have to use a different 'dirty' workstation to post here so I can't simply copy/paste.
Nice. You might try the GMane web interface to its newsgroup for this mailing list next time; you should be able to paste into that. -- Dave Abrahams Boost Consulting www.boost-consulting.com
You need to specify a return value policy when returning pointers and references from functions, because otherwise Boost.Python doesn't know how/whether to manage the lifetime of the thing referred to. In this case, reference_existing_object looks like the right policy. Since GetMyClass has no arguments, return_arg certainly can't be the right choice!
Can you please point me to where I can find an in-depth discussion of return value policies? Are the 6 models under boost::python docs' ConverterGenerator all I can use/need?
P.S. Next time I suggest you copy/paste your actual code and the actual error message. It was specify_a_return_value_policy_to_wrap_functions_returning
Lol, sorry about that. The secret police psychos here at where I work restrict us from performing *very dangerous* actions like downloading MP3's, zip files with source code in them, installing winamp... Ohh and also posting to newsgroups. I have to use a different 'dirty' workstation to post here so I can't simply copy/paste. I'll make an effort to be more accurate in the future. Cheers, Ira
participants (3)
-
David Abrahams -
Ira -
Ira Holtzer