Re: [C++-sig] How to wrap reference to abstract base class to get C++ polymorphism
2010/5/20 Kun Hong
>
>
> class B
> {
> public:
>virtual const char *getName() const = 0;
> };
>
> BOOST_PYTHON_MODULE(Test)
> {
>
>class_
>("B", no_init)
>.def("getName", pure_virtual(&B::getName))
>;
>
>def("getB", &getB,
> return_value_policy());
> }
>
> When you expose your method getName, expose it like a classic method,
without the pure_virtual. The C++ will perform the virtual call itself.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] automatic conversion of tuple to vector
Hi All,
The FAQ at:
http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/faq.html
lists the following code as not possible with boost.python:
C++:
void foo(std::vector& array)
{
for(std::size_t i=0;i>> l = [1, 2, 3]
>>> foo(l)
>>> print l
[2, 4, 6]
Basically, the desired behavior is to have a C++ function which
accepts a vector in C++; accept a tuple/list when in Python.
I'm not sure if the FAQ is up-to-date. Is this still not possible in
boost.python? How do people generally get the behavior I outlined
above?
Thanks!
nathan
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] automatic conversion of tuple to vector
On 05/24/2010 03:00 PM, Nathan Cournia wrote:
Basically, the desired behavior is to have a C++ function which
accepts a vector in C++; accept a tuple/list when in Python.
I'm not sure if the FAQ is up-to-date. Is this still not possible in
boost.python? How do people generally get the behavior I outlined
above?
In general, you'll have to write your own custom wrapper that takes a
boost::python::object argument, and wrap that, to get this behavior:
void py_foo(boost::python::object const & py_array) {
std::vector array;
//
foo(array);
//
}
boost::python::def("foo", &py_foo);
The copies are unavoidable if your C++ function takes a container,
rather than a templated iterator range, simply because your Python
object doesn't actually contain a std::vector. If you can work with an
iterator range, check out my from_python_iterator class, part of the
Python extensions in the boost sandbox:
https://svn.boost.org/trac/boost/browser/sandbox/python_extensions/boost/python/from_python/iterator.hpp
Along with the to-python iterator found in the main Boost.Python
distribution, it should also help in the case where you have to make copies.
HTH
Jim Bosch
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] No to_python (by-value) converter found for C++ type
I am facing a problem while creating python binding for some code in my application. I have created a sample program for that and attached the same to this mail. Here after the generation of python bindings when I try to use that it fails with error No to_python (by-value) converter found for C++ type: CallResult Where as for this example code it even does not shows warning that CallResult is unknown type, still I used sizeof and even in the generated code I could find CallResult class. Attached tar file contains: structEx.cpp (cpp code) ex.py (python code generator script) exWithSizeOf.py (python code generator script using size of) sizeof.h include.h t.py(example python script to use the generated binding ) g++ -fpic -shared -o testModule.so -I/usr/include/python2.4/ -L/usr/lib64/ -lboost_python testModule.cpp (command for compilation) Can you please suggest what I am missing in this case. After some analysis I found, in my case python bindings generated contains line: typedef bp::class_< CallResult< Simple >, boost::noncopyable > CallResult_less__Simple__greater__exposer_t; I could not understand why boost::noncopyable is added as an extra template parameter and this seems to be be culprit in my case. I don't think my class contains object of any class which is derived from boost::noncopyable. Can you please suggest, what I am missing in this case? http://old.nabble.com/file/p28664090/structEx.tar.gz structEx.tar.gz -- View this message in context: http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664090.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
On 05/24/2010 09:03 PM, vishal bayskar wrote: After some analysis I found, in my case python bindings generated contains line: typedef bp::class_< CallResult< Simple>, boost::noncopyable> CallResult_less__Simple__greater__exposer_t; I could not understand why boost::noncopyable is added as an extra template parameter and this seems to be be culprit in my case. It definitely is the culprit. The error you see is Boost.Python doing exactly what the code generator told it to do. I don't think my class contains object of any class which is derived from boost::noncopyable. Can you please suggest, what I am missing in this case? http://old.nabble.com/file/p28664090/structEx.tar.gz structEx.tar.gz I didn't see anything attached to your email, and my tar doesn't like what's at the link above. I'm not sure whatever binding generator you're using (Py++?) uses to determine whether to thrown noncopyable in, there, but I suspect it would do so if you don't have a public copy constructor defined available, even if you didn't use boost::noncopyable to get rid of it. Maybe you can try posting the example again? Jim Bosch ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
>I didn't see anything attached to your email, and my tar doesn't like >what's at the link above. I'm not sure whatever binding generator >you're using (Py++?) uses to determine whether to thrown noncopyable in, >there, but I suspect it would do so if you don't have a public copy >constructor defined available, even if you didn't use boost::noncopyable >to get rid of it. >Maybe you can try posting the example again? zip file is attached below http://old.nabble.com/file/p28664525/structEx.zip structEx.zip I am also attaching important files structEx.cpp http://old.nabble.com/file/p28664525/structEx.cpp structEx.cpp ex.py http://old.nabble.com/file/p28664525/ex.py ex.py I have used py++ (latest version) for code generation -- View this message in context: http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664525.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
On Tue, May 25, 2010 at 8:46 AM, vishal bayskar wrote: > > >>I didn't see anything attached to your email, and my tar doesn't like >>what's at the link above. I'm not sure whatever binding generator >>you're using (Py++?) uses to determine whether to thrown noncopyable in, >>there, but I suspect it would do so if you don't have a public copy >>constructor defined available, even if you didn't use boost::noncopyable >>to get rid of it. > >>Maybe you can try posting the example again? > > zip file is attached below > http://old.nabble.com/file/p28664525/structEx.zip structEx.zip > > I am also attaching important files > structEx.cpp > http://old.nabble.com/file/p28664525/structEx.cpp structEx.cpp > > ex.py > http://old.nabble.com/file/p28664525/ex.py ex.py > > I have used py++ (latest version) for code generation Please post a small and complete code directly to the mailing list. Did you try to remove "noncopyable" from the generated code? If so what happened? If you think, that py++ wrong, you can always override its decision: mb = module_builder_t( ... ) mb.class_(...).noncopyable = False HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
>I suspect it would do so if you don't have a public copy constructor defined available, even if you didn't use boost::noncopyable to get rid of it. Thanks Jim, I have defined public copy constructor explicitly now it is working. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig -- View this message in context: http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664564.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
>Did you try to remove "noncopyable" from the generated code? If so >what happened? Thanks, yes it works when "noncopyable" is removed. >If you think, that py++ wrong, you can always override its decision: >mb = module_builder_t( ... ) >mb.class_(...).noncopyable = False Thanks again it is helpful for us. -- View this message in context: http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664599.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
On Tue, May 25, 2010 at 9:06 AM, vishal bayskar wrote: > > >>Did you try to remove "noncopyable" from the generated code? If so >>what happened? > > Thanks, yes it works when "noncopyable" is removed. > >>If you think, that py++ wrong, you can always override its decision: > >>mb = module_builder_t( ... ) >>mb.class_(...).noncopyable = False > > Thanks again it is helpful for us. It seems, that py++ was wrong :-(. Can you specify gccxml version, OS and your compiler? Do you mind to submit a small test case that reproduce the problem? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
>It seems, that py++ was wrong :-(. Can you specify gccxml version, OS >and your compiler? Do you mind to submit a small test case that >reproduce the problem? gccxml: gccxml-0.9 OS: x86_64-redhat-linux Compiler: gcc version 4.1.2 20080704 (Red Hat 4.1.2-44) You can use the code attached below (please modify it as you require :-)) just run unittest.sh it will give result fail or pass. tar file and zip file both are attached tarfile http://old.nabble.com/file/p28664876/unittest.tar.gz unittest.tar.gz zipfile http://old.nabble.com/file/p28664876/unittest.zip unittest.zip Thanks -- View this message in context: http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664876.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] No to_python (by-value) converter found for C++ type
Hi,
>mb = module_builder_t( ... )
>mb.class_(...).noncopyable = False
This does not works in my case.
Example code is:
enum CallStatus
{
SUCCESS = 423,
FAILURE = 764
};
template
struct CallResult
{
public:
CallResult(CallStatus const callStatus)
: status(callStatus)
{
}
CallResult(CallStatus const callStatus, Result const & result)
: status(callStatus), result(result)
{
}
/*
CallResult(CallResult const& callResult)
{
status = callResult.status;
result = callResult.result;
}
*/
CallStatus const status;
Result const result;
// boost::optional const result;
};
class Simple
{
public:
Simple()
{
}
/*
Simple(Simple const&)
{
}
*/
};
//typedef CallResult cRI;
CallResult getCallResult()
{
Simple si;
return CallResult(SUCCESS, si);
}
And the code generator that I used
import os
from pyplusplus import module_builder
from pyplusplus.module_builder import call_policies
from pyplusplus import code_creators
mb=module_builder.module_builder_t(["./include.h"]
)
mb.enum('CallStatus').include()
mb.class_('Simple').include()
mb.class_('VerifyResult').include()
mb.class_('CallResult').include()
mb.class_('CallResult').noncopyable = False
mb.free_function('getCallResult').include()
mb.build_code_creator( module_name = 'testModule')
mb.write_module('testModule.cpp')
I would like to mention here that, if I remove const from both status and
result, boost::noncopyable is removed.
versions are
g++ (GCC) 4.1.2 20080704,
gccxml-0.9 and
os 2.6.18-128.el5 .
With Regards,
Abhishek Srivastava
Roman Yakovenko wrote:
>
> On Tue, May 25, 2010 at 9:06 AM, vishal bayskar
> wrote:
>>
>>
>>>Did you try to remove "noncopyable" from the generated code? If so
>>>what happened?
>>
>> Thanks, yes it works when "noncopyable" is removed.
>>
>>>If you think, that py++ wrong, you can always override its decision:
>>
>>>mb = module_builder_t( ... )
>>>mb.class_(...).noncopyable = False
>>
>> Thanks again it is helpful for us.
>
> It seems, that py++ was wrong :-(. Can you specify gccxml version, OS
> and your compiler? Do you mind to submit a small test case that
> reproduce the problem?
>
> Thanks
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
--
View this message in context:
http://old.nabble.com/No-to_python-%28by-value%29-converter-found-for-C%2B%2B-type-tp28664090p28664895.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
