[C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial

2008-12-05 Thread kekela
Hi,

I'm new to boost and aiming to use boost:python and I am experiencing 
difficulties with the boost:python tutorial. While running bjam plain (i.e. 
with test targets and without --preserve-test-target or -n -a) creates nice 
test results (i.e. hello, hello.output and hello.test are created with "hello, 
world\n\nEXIT STATUS: 0" as well as "passed"), I cannot import hello_ext in 
python, when bjamming without test targets etc.

But then again, maybe I shouldn't try to import hello_ext.so but have some kind 
of hello_ext.pyd?

Well, what happens is this:

[ release]$ ls
hello_ext.so  hello.o
[ release]$ python
Python 2.4.3 (#1, May 24 2008, 13:57:05) 
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello_ext
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: libboost_python-gcc41-1_37.so.1.37.0: cannot open shared object 
file: No such file or directory


Actually I wasn't able to locate any libboost* files yet, but since the tests 
are passed, I'm probably doing something wrong. Please guide me!

Thank you very much.
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial

2008-12-05 Thread kekela
> Maybe your library path is incorrect. You may try (with bash)
> export LD_LIBRARY_PATH=path_to_your_libboost_python-gcc41-1_37.so.1.37.0

Now it works. Well, yes, there were 3 issues. First, I had skipped the "make 
install" part in "getting started with boost", i.e. I didn't have any libboost* 
files (of which I know explicitly). Second, LD_LIBRARY_PATH was not set and, 
third, libboost_python-gcc41-1_37.so.1.37.0 didn't exist after making. I just 
copied "libboost_python-gcc41-mt-1_37.so.1.37.0" to 
"libboost_python-gcc41-1_37.so.1.37.0" in $LD_LIBRARY_PATH/.

Thank you very much for your quick response.
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Custom from-python converter (almost working)

2008-12-05 Thread pyplusplus
I'm trying to add some custom from-python converters to my bindings (see
code at the end of the mail).
These basically should convert Python 3-tuples of floats to a C++ vec3f
instance. I can't seem to find reference docs on classes related to
conversion, e.g. boost::python::converter::registry, so after some
googling and experimenting I think the code at the end of this mail is a
pretty clean implementation of what I want, and it almost fully works:

Python 2.4.3 (#1, Jun 13 2006, 16:41:18)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import doh
>>> doh.f((1,2,3))
1.00, 2.00, 3.00
>>> doh.p((1,2,3))
Traceback (most recent call last):
  File "", line 1, in ?
Boost.Python.ArgumentError: Python argument types in
doh.p(tuple)
did not match C++ signature:
p(vec3f*)
>>>

So the implicit conversion to a pointer to a vec3f doesn't work. After
some more googling I came across the thread [1], which seemed to suggest
that there is another way of registering a converter, i.e.

"""
Don't try to convert to pointers; there are no pointers in
Boost.Python; only lvalues and rvalues ;-)

  void* extract_foo(PyObject* op)
  {
  return FooObject_ptr(op);
  }

  boost::python::converter::registry::insert(
&extractor_foo, boost::python::type_id());
"""

In the February 2002 progress report [2] (does that reflect the current
situation in 1.37 w.r.t. to/from-python converters, b.t.w?) it says:

"""There are basically two categories of from_python conversions:
those which lvalues stored within or held by the Python object
(essentially extractions), like what happens when an instance of a
C++ class exposed with class_ is used as the target of a wrapped
member function), and those in which a new rvalue gets created, as
when a Python Float is converted to a C++ complex or a Python
tuple is converted to a C++ std::vector<>"""

It seems my non-working case of conversion to a vec3f* is of the latter
category.

Can I assume that the two different ways of registering a converter
reflect these categories?

If so, then I don't see a way to make this work, as I need actual
conversion, not extraction, i.e. I need to create a new object that
doesn't exist yet. Or should I register my converter in both ways to the
registry?

Any help is greatly appreciated,

Regards,
Paul

[1] http://mail.python.org/pipermail/cplusplus-sig/2006-November/011269.html
[2] http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/feb2002.html




#include 

namespace bp = boost::python;

struct vec3f
{
vec3f(): x(0), y(0), z(0) {}

vec3f(float xx, float yy, float zz)
{
x = xx; y = yy; z = zz;
}

float x, y, z;
};

struct convert_py_tuple_to_vec3f
{
convert_py_tuple_to_vec3f()
{
bp::converter::registry::push_back(
&convertible,
&construct,
bp::type_id());
}

// Check if given Python object is convertible to a vec3f.
// If so, return obj, otherwise return 0
static void* convertible(PyObject* obj)
{
if (PyTuple_Check(obj))
return obj;

return 0;
}

// Construct a vec3f object from the given Python object, and
// store it in the stage1 (?) data.
static void construct(PyObject* obj,
bp::converter::rvalue_from_python_stage1_data* data)
{
// Fill in values
float x, y, z;
if (!PyArg_ParseTuple(obj, "fff", &x, &y, &z))
{
// Raise exception, error will have been set by PyArg_ParseTuple
boost::python::throw_error_already_set();
}

typedef bp::converter::rvalue_from_python_storage
vec3f_storage;
void* const storage =
reinterpret_cast(data)->storage.bytes;
vec3f *v = new (storage) vec3f(x, y, z);

data->convertible = storage;
}
};

void
f(vec3f v)
{
printf("%f, %f, %f\n", v.x, v.y, v.z);
}

void
p(vec3f *v)
{
printf("%f, %f, %f\n", v->x, v->y, v->z);
}

BOOST_PYTHON_MODULE(doh)
{
bp::class_< vec3f >("vec3f")
.def(bp::init())
;

bp::def("f", &f);
bp::def("p", &p);

convert_py_tuple_to_vec3f();
}


___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] [py++] Problem: empty xml file created

2008-12-05 Thread Marcus Lindblom

Marcus Lindblom wrote:

Marcus Lindblom wrote:

(I don't think the gccxml-call happens because of the call to the 
ModuleBuilder at line 813, although I might be wrong?)


Waitaminute. When I'm rerunning it now, the order makes more sense, and 
the cache-calls come up after the calls to ModuleBuilder. Probably the 
log-file merging of stdout and stderr was playing tricks on me.


I'll look augmenting the ModuleBuilder call, just as you said. Sorry for 
the confusion. :-/


I've gotten it to work. :) Now I just have to try to make it parse 
successfully, which it doesn't. :-/


How does gccxml work in compiler-work-alike mode?

I've built with VS9, and am going to compile the wrappers with VS9, so I 
suppose I have to tell gccxml and the code to behave like that, with 
defines and all? (Or should that happen automatically?)


Namely, I get some compile errors from gccxml on code that VS9 accepted, 
so I'm trying to figure out how to approach the problem, before going 
into specifics.


Cheers,
/Marcus
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Custom from-python converter (almost working)

2008-12-05 Thread Ralf W. Grosse-Kunstleve
> void

> p(vec3f *v)
> {
> printf("%f, %f, %f\n", v->x, v->y, v->z);
> }

This is indeed not supported, since it would require "converters with 
write-back".

vec3f const* v

should work, but

ve3f* v

doesn't because the missing const indicates that you want to modify the pointee 
in place.
For a Python tuple this can definitely not work since tuples are immutable.
It could in theory work for a Python list, but Boost.Python doesn't support 
this.
A few years ago we had extensive discussions about this, but it was too hard to
implement.

Ralf

P.S.: I'm using this seasoned file for all "list/tuple/iter <-> small C++ 
array" conversions:

http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/boost_python/container_conversions.h?view=markup

Probably, all you need is

  tuple_mapping_fixed_capacity
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] [py++] Problem: empty xml file created

2008-12-05 Thread Roman Yakovenko
On Fri, Dec 5, 2008 at 5:01 PM, Marcus Lindblom <[EMAIL PROTECTED]> wrote:
> How does gccxml work in compiler-work-alike mode?

I am not sure what you mean by this. GCC-XML doesn't tries to emulate
other compilers. The configuration is used to find system and C++
header files.

> I've built with VS9, and am going to compile the wrappers with VS9, so I
> suppose I have to tell gccxml and the code to behave like that, with defines
> and all? (Or should that happen automatically?)

In your case, it doesn't really matter. Just select the compiler
GCCXML supports better. I think this is one of Visual Studio 2003 or
2005.

> Namely, I get some compile errors from gccxml on code that VS9 accepted, so
> I'm trying to figure out how to approach the problem, before going into
> specifics.

The bottom line - you will have to change the code. GCCXML defines
__GCCXML__ define. (http://gccxml.org/HTML/Running.html ). So you can
introduce the changes for this compiler only.

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial

2008-12-05 Thread Adrien Saladin
> Now it works. Well, yes, there were 3 issues. First, I had skipped the "make 
> install" part in "getting started with boost", i.e. I didn't have any 
> libboost* files (of which I know explicitly). Second, LD_LIBRARY_PATH was not 
> set and, third, libboost_python-gcc41-1_37.so.1.37.0 didn't exist after 
> making. I just copied "libboost_python-gcc41-mt-1_37.so.1.37.0" to 
> "libboost_python-gcc41-1_37.so.1.37.0" in $LD_LIBRARY_PATH/.
>
> Thank you very much for your quick response.


You're welcome.
I remember that you mentioned bjam, and if you like it then continue
with it, but don't trust the documentation website: many other tools
can compile and link with boost.python, not only bjam. I'm using SCons
but make and cmake works as well.

I'm telling that because I really dislike bjam syntax and when I began
with boost.python I thought that boost.python was not for me just
because of this building tool.

Also if you begin with boost.python you must have a look at pyplusplus
(or Py++), it's a very convenient tool that parses your C++ headers
and generates boost.python code almost automatically. I'm using it for
two years now and I'm really happy with it.

There is also one problem with boost.python in general: library tends
to become bigger and bigger with the number of functions and classes
that you interface. Compile-time may also become an issue at some
point. My library (~7000 lines of C++, 15 classes) now takes 50sec on
a 8 cores 3Ghz computer. About 45sec are for the boost.python
bindings...
I'm now considering switching to pybindgen, but it's still a very new
project that lacks some features of boost.python.

Just curious, for what type of project do you wish to learn boost.python ?

Best,
Adrien
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig