[C++-sig] Linking to libboost_python, on Ubuntu - I've forgotten something...

2008-11-16 Thread Simon Pickles

Hello,

I am setting up boost python on a new Ubuntu system. I thought I had 
everything configured correctly, but think I may have missed a vital step.


When I run the python program which attempts to use the library 
generated by bjam, I get this:


[EMAIL PROTECTED]:~/WorkingCopies/server/trunk/hybrid_test$ python 
hybridTest.py

Traceback (most recent call last):
 File "hybridTest.py", line 2, in 
   import Hybrid
ImportError: libboost_python-gcc42-d-1_37.so.1.37.0: cannot open shared 
object file: No such file or directory



I have built boost 1.37.0 from source using:

sudo bjam -sPYTHON_ROOT=/usr/local/lib/python25 -sPYTHON_VERSION=2.5 
--build-type=complete --toolset=gcc stage


(its a stackless python build in /usr/local/lib/python25)

I've set the config files I think:

#--
# user-config.jam in home directory

# Compiler configuration
using gcc ;

# Python configuration
using python : 2.5 : /usr/local/bin/python ;
#-

# boost-build.jam in project folder
boost-build /home/simon/Source/boost_1_37_0/tools/build/v2 ;

#-

# jamroot in project folder

use-project boost
 : /home/simon/Source/boost_1_37_0 ;


# Set up the project-wide requirements that everything uses the
# boost_python library defined in the project whose global ID is
# /boost/python.
project Hybrid
 : requirements /boost/python//boost_python
   /home/simon/Source/bullet-2.72/src
   
/home/simon/Source/boost_1_37_0/stage/lib/libboost_python-gcc42-d-1_37.so.1.37.0

   ;

## Make the definition of the python-extension rule available
import python ;

# Declare a Python extension
python-extension Hybrid : [ glob Log/*.cpp ] [ glob Object/*.cpp ] [ 
glob World/*.cpp ] HybridModule.cpp ;

install . : Hybrid ;

#-

This build successfully with bjam, and I am left with the expected 
Hybrid.so in the project folder.


As you can see from the jamroot file, I've even tried directly 
specifying the library libboost_python-gcc42-d-1_37.so.1.37.0


Can anyone suggest where I have missed a trick?

Many thanks

Simon


--
Linux User# 424693 





___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Linking to libboost_python, on Ubuntu - I've forgotten something...

2008-11-17 Thread Simon Pickles



Kirit Sælensminde wrote:

Simon Pickles wrote:
When I run the python program which attempts to use the library 
generated by bjam, I get this:


[EMAIL PROTECTED]:~/WorkingCopies/server/trunk/hybrid_test$ python 
hybridTest.py

Traceback (most recent call last):
 File "hybridTest.py", line 2, in 
   import Hybrid
ImportError: libboost_python-gcc42-d-1_37.so.1.37.0: cannot open 
shared object file: No such file or directory



I have built boost 1.37.0 from source using:

sudo bjam -sPYTHON_ROOT=/usr/local/lib/python25 -sPYTHON_VERSION=2.5 
--build-type=complete --toolset=gcc stage


Looks like you don't have the .so anywhere it can be found. You want 
to either set LD_LIBRARY_PATH to the location of your Boost .so files, 
or you can use the  Bjam option to hard code the paths in 
your build Python .so.


You could also install the Boost files to somewhere they will be found 
(/usr/local/lib/ should do).



That did the trick - Thanks

Sure I didn't have to do that last time - never mind. It works and I can 
progress!


K

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig




--


Latest NEWS >> http://www.science-projects.org/news.html

Our PORTFOLIO is online at >> 
http://www.science-projects.org/workshop/portfolio/index.html

Science Projects
20 St James Street
Hammersmith
London
W6 9RW
t: +44 (0)20 8741 2305
f: +44 (0)20 8741 2307

http://www.science-projects.org
http://www.the-observatory.org
http://www.inspirediscoverycentre.org


Science Projects Ltd. is a company limited by guarantee registered in England 
No: 02186073 and a registered Charity No. 298542. Its registered office address 
is 20 St James Street, Hammersmith, London W6 9RW.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Need help with inheritance problem

2008-12-12 Thread Simon Pickles

Hi,

I am trying to expose part of the bullet dynamics library to my python code.

I simply need to expose a few accessors of a type btVector3. This 
inherits from a class which is itself derived. I seem to be struggling 
to get this right.


Here is my attempt:

BOOST_PYTHON_MODULE(HybridZone)
{
   using namespace boost::python;

   class_("btQuadWordStorage")
   ;
  
   // I am trying to expose getX()

   class_ >("btQuadWord")
   .def("getX", &btQuadWord::getX, return_internal_reference<1, 
with_custodian_and_ward<1, 2> >());

   //.add_property("x", &btQuadWord::x) // doesn't compile either
   ;
  
   class_ >("btVector3", initfloat, float>())

   ;
}

You can see my structure is an attempt to mimic the inheritance diagram 
found here


http://www.continuousphysics.com/Bullet/BulletFull/classbtVector3.html

I am trying to expose btVector3::getX(), inherited from btQuadWord

Thanks for your time and advice.

Simon

ps: heres the error message, on gcc4.2.4, Ubuntu 8.04:

...updating 3 targets...
gcc.compile.c++ bin/gcc-4.2.4/debug/HybridZone.o
/home/simon/Source/boost_1_37_0/boost/python/object/make_instance.hpp: 
In static member function \u2018static PyObject* 
boost::python::objects::make_instance_implDerived>::execute(Arg&) [with Arg = float*, T = float, Holder = 
boost::python::objects::pointer_holder, Derived = 
boost::python::objects::make_ptr_instanceboost::python::objects::pointer_holder >]\u2019:
/home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:106:   
instantiated from \u2018static PyObject* 
boost::python::detail::make_reference_holder::execute(T*) [with T = 
float]\u2019
/home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:70:   
instantiated from \u2018PyObject* boost::python::to_python_indirectMakeHolder>::execute(const U&, mpl_::false_) const [with U = float, T = 
const float&, MakeHolder = 
boost::python::detail::make_reference_holder]\u2019
/home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:41:   
instantiated from \u2018PyObject* boost::python::to_python_indirectMakeHolder>::operator()(const U&) const [with U = float, T = const 
float&, MakeHolder = boost::python::detail::make_reference_holder]\u2019
/home/simon/Source/boost_1_37_0/boost/python/detail/invoke.hpp:88:   
instantiated from \u2018PyObject* 
boost::python::detail::invoke(boost::python::detail::invoke_tag_true>, const RC&, F&, TC&) [with RC = 
boost::python::to_python_indirectboost::python::detail::make_reference_holder>, F = const btScalar& 
(btQuadWord::*)()const, TC = 
boost::python::arg_from_python]\u2019
/home/simon/Source/boost_1_37_0/boost/python/detail/caller.hpp:223:   
instantiated from \u2018PyObject* 
boost::python::detail::caller_arity<1u>::implSig>::operator()(PyObject*, PyObject*) [with F = const btScalar& 
(btQuadWord::*)()const, Policies = 
boost::python::return_internal_reference<1u, 
boost::python::with_custodian_and_ward<1u, 2u, 
boost::python::default_call_policies> >, Sig = boost::mpl::vector2btScalar&, btQuadWord&>]\u2019
/home/simon/Source/boost_1_37_0/boost/python/object/py_function.hpp:38:   
instantiated from \u2018PyObject* 
boost::python::objects::caller_py_function_impl::operator()(PyObject*, 
PyObject*) [with Caller = boost::python::detail::caller(btQuadWord::*)()const, boost::python::return_internal_reference<1u, 
boost::python::with_custodian_and_ward<1u, 2u, 
boost::python::default_call_policies> >, boost::mpl::vector2btScalar&, btQuadWord&> >]\u2019

HybridZone.cpp:88:   instantiated from here
/home/simon/Source/boost_1_37_0/boost/python/object/make_instance.hpp:24: 
error: invalid application of \u2018sizeof\u2019 to incomplete type 
\u2018boost::STATIC_ASSERTION_FAILURE\u2019


   "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC  
-DBOOST_DATE_TIME_DYN_LINK=1 -DDATE_TIME_INLINE  
-I"/home/simon/Source/boost_1_37_0" 
-I"/home/simon/Source/bullet-2.72/src" -I"/usr/local/include/python2.5" 
-c -o "bin/gcc-4.2.4/debug/HybridZone.o" "HybridZone.cpp"


...failed gcc.compile.c++ bin/gcc-4.2.4/debug/HybridZone.o...
...skipped HybridZone.so for lack of 
HybridZone.o...
...skipped HybridZone.so for lack of 
HybridZone.so...

...failed updating 1 target...
...skipped 2 targets...

--
Linux Counter: User# 424693 




___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Extended python system needs access to cPickle in c++

2009-05-05 Thread Simon Pickles

Hi,

I have an app with a python core, then c++ extension modules.

I'd like to be able to use cPickle to pack structures, especially 
boost::python::tuples, in c++.


Is there a way I can expose a python module in the c++ extensions?

I thought about passing a module as an arg to a c++ function, as a 
boost::python::object:


// cModule

void DoStuff(object pickleModule)
{
   tuple t = make_tuple("Spam",42);
   object pickleDumps = pickleModule.attr("dumps");
   object s = pickleDumps(t);

   // Send s to other process
}



# python
import cModule
import cPickle

cModule.DoStuff(cPickle)
#

Am I barking up the wrong tree?

Many thanks

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Trouble reinstalling boost

2009-05-15 Thread Simon Pickles

Hi,

I had a nice build system set up on my VM ubuntu 8.10 server until I 
broke the VM. :) After rebuild the VM I am obviously reinstalling all 
the packages.


Boost Python is causing me trouble. I built it from svn using bjam, 
boost 1_40_0. I can compile my python extension without error but when I 
run it the python code that uses it, I get:


ImportError: libboost_python-gcc43-d-1_40.so.1.40.0: cannot open shared 
object file: No such file or directory


I have this file on my system, and have copied it to /usr/local/lib

si...@fenixurth:~/WorkingCopies/server/extended$ locate 
libboost_python-gcc43-d-1_40.so.1.40.0

/home/simon/source/boost/bin.v2/libs/python/build/gcc-4.3.2/debug/libboost_python-gcc43-d-1_40.so.1.40.0
/home/simon/source/boost/stage/lib/libboost_python-gcc43-d-1_40.so.1.40.0
/home/simon/WorkingCopies/server/extended/libboost_python-gcc43-d-1_40.so.1.40.0
/usr/local/lib/libboost_python-gcc43-d-1_40.so.1.40.0


Why is this not found?

Thanks

Simon

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Getting a c++ pointer from a python object

2009-06-08 Thread Simon Pickles

Hi,

I am trying to get a c++ pointer to a python object.

I am using DirectPython, and a function in that library, getDevice(), 
"returns the address of the object" - a IDirect3DDevice9*, already 
created using DirectPython code.


Using boost::python, I have an extension module function with this
signature:

// c++
void TestClass::Init( IDirect3DDevice9* device );

I tried to call this function with:

#python, called after device is created:
from testClass import TestClass
test = TestClass()
test.Init( d3d.getDevice() )

Here's the error I get:
##
Traceback (most recent call last):
  File "client.py", line 31, in __init__
test.Init(d3d.getDevice())
Boost.Python.ArgumentError: Python argument types in
TestClass.Init(TestClass, long)
did not match C++ signature:
Init(class TestClass {lvalue}, struct IDirect3DDevice9 *)
##

But got a type mismatch. DirectPython gives the address as a long, when 
c++ wants a pointer to a struct.


I then tried this with the same python calling code:

void TestClass::Init(void* deviceAddress)
{
IDirect3DDevice9* m_device = 
static_cast(deviceAddress);

}

Of course I get a similar error:

##
Traceback (most recent call last):
  File "client.py", line 33, in __init__
test.Init(d3d.getDevice())
Boost.Python.ArgumentError: Python argument types in
TestClass.Init(TestClass, long)
did not match C++ signature:
Init(class TestClass {lvalue}, void *)
##

How can I get the address from python to c++?

Thanks

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Avoiding copying non-copyables

2009-06-15 Thread Simon Pickles

Hi,

I have a c++ class which uses boost::thread and boost::mutex.

I cannot expose this class directly with boost::python, since mutex is 
non-copyable.


so I did this:

/// C++
class ResourceManager
{};

ResourceManager* ResourceManagerFactory()
{
return new ResourceManager();
}

def("ResourceManagerFactory", ResourceManagerFactory, 
return_value_policy());





This compiles but I at python runtime I get:

# PYTHON
self.resourceManager = ResourceManagerFactory()
TypeError: No Python class registered for C++ class class ResourceManager

#

Am I doing this wrong? Wrong return policy?

Thanks

Simon


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] boost::python and __declspec(align(16))

2009-06-18 Thread Simon Pickles

Hi,

I think this is an MSVC problem caused by the bad STL implementation, 
but I wondered if there was a work around.


Both my client (Win32 MSVC8) and server (ubuntu GCC 4.2.3) share the 
same c++ code. It compiles and runs on GCC but fails on MSVC.


This uses the the bullet physics library and includes a type defined 
like this:


__declspec(align(16)) btVector3 {/*...*/};

When building my boost::python extension with:

class_("BtVector3", init());

I get an error like this :

C:\boost_1_38_0\boost/python/converter/as_to_python_function.hpp(21) : 
error C2719: 'unnamed-parameter': formal parameter with 
__declspec(align('16')) won't be aligned
   C:\boost_1_38_0\boost/python/to_python_converter.hpp(88) : see 
reference to class template instantiation 
'boost::python::converter::as_to_python_function' being compiled

   with
   [
   T=btVector3,
   /*  Huge call stack omitted for clarity */
   build.cpp(155) : see reference to class template instantiation 
'boost::python::class_' being compiled

   with
   [
   W=btVector3
   ]

Is there a way to overcome this? switch to MinGW? :)

Thank you very much

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Boost.Python and STLPort, ArgumentError

2009-06-19 Thread Simon Pickles

Hello,

Configuration:
WinXP SP3
MSVC8
Python 2.5.4
Boost 1.38
STLPort 5.2
Bullet Physics (requires STLPort to avoid Alignment problems)

I need to use STLPort with my c++ extension modules, due to Bullet 
Physics API.


I've managed to build STLPort, rebuilt boost (bjam stllib=stlport 
stage), and rebuild my project (bjam define=__STL_DEBUG). My problem 
starts when I run my python code. This calls c++ modules, and I get a 
type mismatch:


E:\WorkingCopies\client\extended>python client.py
Traceback (most recent call last):
 File "client.py", line 232, in 
   log.StartLogToFile("Log_Client.txt")
Boost.Python.ArgumentError: Python argument types in
   None.None(Logger, str)
did not match C++ signature:
   None(class Logger {lvalue}, class stlpd_std::basic_stringstlpd_std::char_traits,class stlpd_std::allocator >)


Clearly, the c++ module, built with stlport, is expecting an 
stlp::string while the calling python code is providing a std::string 
(eg a python string)


Please don't tell me I have to rebuild python using stlport? I have not 
had much success building python from source in the past! :)


Is there a simpler remedy for this hopefully small hurdle?

Thank you for your help

Simon

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost.Python and STLPort, ArgumentError

2009-06-19 Thread Simon Pickles

Hello Nikolay,

Thanks for the reply.

I _think_ it is built with stlport. I rebuilt boost.python with my 
user-config.jam changed and the stdlib=stlport option. It generated new 
libraries with the 'p' suffix (for stlport)


When I bjammed my c++ extension module, I had to link to the 
boost_python-xxx-gdp.lib files and it required the dll counterparts to 
build and run


Perhaps I need to build my project with:

bjam define=__STL_DEBUG stdlib=stlport

I will try on the train home :)

Thanks

Simon

Nikolay Mladenov wrote:

It looks like your Boost.Python requires rebuild with stlport?
The error message comes from Boost.Python (function.cpp I think).
It seems to me that your module is build with stlport but boost_python 
is not.


HTH,

Nikolay


Simon Pickles wrote:

Hello,

Configuration:
WinXP SP3
MSVC8
Python 2.5.4
Boost 1.38
STLPort 5.2
Bullet Physics (requires STLPort to avoid Alignment problems)

I need to use STLPort with my c++ extension modules, due to Bullet 
Physics API.


I've managed to build STLPort, rebuilt boost (bjam stllib=stlport 
stage), and rebuild my project (bjam define=__STL_DEBUG). My problem 
starts when I run my python code. This calls c++ modules, and I get a 
type mismatch:


E:\WorkingCopies\client\extended>python client.py
Traceback (most recent call last):
 File "client.py", line 232, in 
   log.StartLogToFile("Log_Client.txt")
Boost.Python.ArgumentError: Python argument types in
   None.None(Logger, str)
did not match C++ signature:
   None(class Logger {lvalue}, class 
stlpd_std::basic_string,class 
stlpd_std::allocator >)


Clearly, the c++ module, built with stlport, is expecting an 
stlp::string while the calling python code is providing a std::string 
(eg a python string)


Please don't tell me I have to rebuild python using stlport? I have 
not had much success building python from source in the past! :)


Is there a simpler remedy for this hopefully small hurdle?

Thank you for your help

Simon


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig



___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] bump.... boost::python and __declspec(align(16))

2009-06-23 Thread Simon Pickles


Hello all,

Sorry to bump this, but i am still unable to resolve my problem 
described below.


I have seen a 2008 thread on this: 
http://archives.free.net.ph/message/20080331.203857.548691a0.ja.html


In this case it is align(8) not align(16), and the thread describes this 
issue as resolved. This leads me to believe there is an answer *out 
there* :)


Thanks for your help

Simon


Hi,

I think this is an MSVC problem caused by the bad STL implementation,
but I wondered if there was a work around.

Both my client (Win32 MSVC8) and server (ubuntu GCC 4.2.3) share the
same c++ code. It compiles and runs on GCC but fails on MSVC.

This uses the the bullet physics library and includes a type defined
like this:

__declspec(align(16)) btVector3 {/*...*/};

When building my boost::python extension with:

class_("BtVector3", init());

I get an error like this :

C:\boost_1_38_0\boost/python/converter/as_to_python_function.hpp(21) :
error C2719: 'unnamed-parameter': formal parameter with
__declspec(align('16')) won't be aligned
C:\boost_1_38_0\boost/python/to_python_converter.hpp(88) : see
reference to class template instantiation
'boost::python::converter::as_to_python_function' being compiled
with
[
T=btVector3,
/*  Huge call stack omitted for clarity */
build.cpp(155) : see reference to class template instantiation
'boost::python::class_' being compiled
with
[
W=btVector3
]

Is there a way to overcome this? switch to MinGW? :)

Thank you very much

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] bump.... boost::python and __declspec(align(16))

2009-06-23 Thread Simon Pickles

Stefan Seefeld wrote:

On 06/23/2009 02:05 PM, Simon Pickles wrote:


Hello all,

Sorry to bump this, but i am still unable to resolve my problem 
described below.


The problem doesn't appear to be related to boost.python, or even boost. 
You may have better luck asking on a more suitable forum.


Stefan




I thought someone might say that. Maybe when more experienced, I will be 
able to ascertain that myself.


Thanks Stefan.

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Passing a c++ new'ed object back to python

2009-06-23 Thread Simon Pickles

Hello again.

Here's the setup

#python
from hybrid import ObjectManager

om = ObjectManager()
om.PassModel()


//cpp
class Model
{
~Model()
{
printf("model go boom");
}
/* */
};

class ObjectManager
{
Model* PassModel()
{
return new Model();
};
};


When I use code which parallels this structure, I see the Model 
destructor is called when the c++ object goes out of scope (fine) 
despite the object being passed to python as the argument of a function 
(not fine!)


Is there a return policy I need to provide? I am confused by the way the 
destructing class is new'ed in c++ code, not in python by using exposed c++.


Better luck this time :)

Simon





___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Uh-oh now I am trying boost python embedding

2009-06-25 Thread Simon Pickles

Hi

I've got an embedded python system up and running, for evaluation purposes.

I am able to expose c++ modules to python, create c++ classes in python, 
and extract and use those python types in c++! Cool!


However, what if I want to pass a c++ type to a python class? Is there 
some way to covnert my class, Logger in this case, to an bpy object, or 
some other way?


Here's my code:

// main.cpp
#include 
#include 
#include 
#include "../logger/logger.h"

using namespace boost::python;
using namespace std;

BOOST_PYTHON_MODULE(hybrid)
{
   class_("Logger")
   .def("StartLogToFile", &Logger::StartLogToFile)
   .def("SYS", &Logger::SYS)
   ;
}

int main(int, char **)
{
   Py_Initialize();
   try
   {
   // Get main module and namespace
   object 
pyModule_main(handle<>(borrowed(PyImport_AddModule("__main__";

   object pyNamespace_main = pyModule_main.attr("__dict__");

   // expose boost python modules
   inithybrid();
   exec("print 'Embedded python'\n", m_pyNamespace_main);
  
  
   // import another module

   object pyModule_test = import("test");
   object pyNamespace_test = pyModule_test.attr("__dict__");   

   // c++ object, creating in python, extracted and used in c++! 
THIS WORKS

   Logger* log = extract(pyNamespace_test["pyLogger"]);
   log->SYS("C++ using an object created in python embedded in 
c++!", 0);


   Logger* cppLogger = new Logger;
   cppLogger->StartLogToFile("cppLog.txt");
   //Push c++ logger into python namespace THIS DOESN'T!
   pyNamespace_test["logger"] = cppLogger;

   object ignored = exec("useCppLogger()", m_pyNamespace_test, 
m_pyNamespace_test);


   }
   catch (error_already_set)
   {
   PyErr_Print();
   }

   delete cppLogger;
}


# test.py
import hybrid
pyLogger = hybrid.Logger()
pyLogger.StartLogToFile("pyLogger.txt")
pyLogger.SYS("Python using a python Logger. wow...")

def useCppLogger():
   # cppLogger has been pushed into module namespace by c++
   global cppLogger
   cppLogger.SYS("Python using a Logger class passed from c++")

#

Thanks for any help!

Simon


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] boost::python::make_tuple crashing

2009-07-05 Thread Simon Pickles

Hi,

I can't figure why the test program is crashing. I am comparing speeds 
of boost::python::tuple and boost::any as variable length application 
message wrappers.


#include "boost//any.hpp"
#include "boost//python.hpp"
#include 
#include 
// RakNet::GetTime for accurate millisecond timimg
#include "GetTime.h"
#include 
#include 
using namespace std;

void HandleBoostAny( const vector& ba)
{
   const string s = boost::any_cast(ba[0]);
   const float f = boost::any_cast(ba[1]);
   const int ui = boost::any_cast(ba[2]);
}
void HandleBoostPythonTuple( const boost::python::tuple& b)
{
   const string s = boost::python::extract(b[0]);
   const float f = boost::python::extract(b[0]);
   const int ui = boost::python::extract(b[2]);
}
int _tmain(int argc, _TCHAR* argv[])
{
   int count = 0;
   int target = 10;
   string s = "spam";
   unsigned char i = 42;
   float f = 3.14f;

   //cout << "Starting boost.any test" << endl;
   //RakNetTime baStart = RakNet::GetTime();
   //for ( count = 0; count < target; ++count )
   //{
   //vector ba;
   //ba.push_back(boost::any(s));
   //ba.push_back(boost::any(f));
   //ba.push_back(boost::any(i));
   //HandleBoostAny(ba);
   //}
   //RakNetTime baEnd = RakNet::GetTime();
   //cout << "Duration: " << (baEnd - baStart) << endl;
   
   cout << "Starting boost.python.tuple test" << endl;
   RakNetTime bptStart = RakNet::GetTime();
   for ( count = 0; count < target; ++count )
   {
   boost::python::tuple bpt = boost::python::make_tuple(s,f);

   HandleBoostPythonTuple(boost::python::make_tuple(f));
   }
   RakNetTime bptEnd = RakNet::GetTime();
   cout << "Duration: " << (bptEnd - bptStart) << endl;
   return 0;
}


I am getting an access violation here, on WinXP SP3, boost 1.38:

python25.dll!1e07de69()
[Frames below may be incorrect and/or missing, no symbols loaded 
for python25.dll]   
>
speedTest.exe!boost::python::converter::arg_to_python::arg_to_python(const 
int & x=0)  Line 113 + 0x31 bytesC++

speedTest.exe!boost::python::api::object_initializer_impl<0,0>::get(const 
int & x=0, boost::mpl::bool_<0> __formal={...})  Line 374 + 0xf bytesC++

speedTest.exe!boost::python::api::object_base_initializer(const int 
& x=0)  Line 296 + 0x10 bytesC++
speedTest.exe!boost::python::api::object::object(const int & 
x=0)  Line 316 + 0x2c bytesC++

speedTest.exe!boost::python::api::object_operators::operator[](const 
int & key=0)  Line 53 + 0xf bytesC++
speedTest.exe!HandleBoostPythonTuple(const boost::python::tuple & 
b={...})  Line 21 + 0x27 bytesC++

speedTest.exe!main()  Line 59 + 0x35 bytesC++
speedTest.exe!__tmainCRTStartup()  Line 586 + 0x19 bytesC
speedTest.exe!mainCRTStartup()  Line 403C
kernel32.dll!7c817077()


I can use make tuple in other programs, but cant see why not here.

Thanks for any advice

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost::python::make_tuple crashing

2009-07-05 Thread Simon Pickles

Sorry, had a typo or two:

#include "boost//any.hpp"
#include "boost//python.hpp"
#include 
#include 
// RakNet::GetTime for accurate millisecond timimg
#include "GetTime.h"
#include 
#include 

using namespace std;

void HandleBoostPythonTuple( const boost::python::tuple& b)
{
   const string s = boost::python::extract(b[0]);
   const float f = boost::python::extract(b[1]);
   const int ui = boost::python::extract(b[2]);
}

int main()
{
   int count = 0;
   int target = 10;

   string s = "spam";
   unsigned char i = 42;
   float f = 3.14f;

   cout << "Starting boost.python.tuple test" << endl;
   RakNetTime bptStart = RakNet::GetTime();
   for ( count = 0; count < target; ++count )
   {
   HandleBoostPythonTuple(boost::python::make_tuple(s,f,i));
   }
   RakNetTime bptEnd = RakNet::GetTime();
   cout << "Duration: " << (bptEnd - bptStart) << endl;
   return 0;
}

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] building modules with MSVC

2009-11-25 Thread Simon Pickles

Hi,

Is it possible to build boost::python modules using MSVC as opposed to bjam?

I'd like MSVC to output a pyd of course.

Thanks

Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Boost Python Tuple - Find length of tuple?

2010-01-04 Thread Simon Pickles

Hello,

I have a simple question. How do I find out in c++ how many elements are 
contained within a boost::python::tuple?


I tried this:

   using namespace boost::python;
   tuple a = make_tuple("hello", 42);
   object b = a.attr("length"); // exception
   unsigned int c = extract(b);
   assert( c==2 );

AttributeError: 'tuple' object has no attribute 'length'

Am I missing something?

Thanks

Si
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost Python Tuple - Find length of tuple?

2010-01-04 Thread Simon Pickles

On 04/01/2010 14:02, Brian O'Kennedy wrote:

You could try this instead: (untested!)

  using namespace boost::python;
  tuple a = make_tuple("hello", 42);
  std::cout << "Length = " << boost::python::len(a) << std::endl; 
 // explicit namespace not needed




Thanks, thats perfect.


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] boost 1.41 and autolink (maybe the wrong list)

2010-01-06 Thread Simon Pickles

Hello Terry,

Try this:

.sconf_temp\conftest_4.cpp:

#define BOOST_PYTHON_DYN_LINK
#include "boost/python.hpp"

This will make boost look for shared library in the autolink feature

Si

On 06/01/2010 06:50, [email protected] wrote:


I have compiled boost, and now want to use it in my python app but I 
am having trouble with autolink.hpp in my c++ files.


C:\source\esys13>cl /Fo.sconf_temp\conftest_4.obj /c 
.sconf_temp\conftest_4.cpp /TP /nologo


/IC:\python26\include "/IC: \source\boost_1_41_0"

conftest_4.cpp

C:\source\boost_1_41_0\boost/config/auto_link.hpp(297) : fatal error 
C1189: #error :  "Mixing a dll boost


 library with a static runtime is a really bad idea..."

I haven't done any linking at this point -- I am just trying to compile.

Here is my test file.

.sconf_temp\conftest_4.cpp:

#include "boost/python.hpp"

Yep -- just the include and thats it.

VS2008, and python 2.6

Any ideas what I am doing wrong?

Terry Rankine


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] Returning a simple char *

2010-01-12 Thread Simon Pickles

Hello,

I thought I was trying to do something simple.

While wrapping a 3rd party library, I have a c++ class with two member 
function returning pointers like this:


class videoInput
{
public:
   static char * getDeviceName(int deviceID);
   
};

and a module like this:

#include "boost//python.hpp"
#include "videoInput.h"

using namespace boost::python;
BOOST_PYTHON_MODULE(pyVideoInput)
{
   class_("videoInput")
   .def("getDeviceName",
   &videoInput::getDeviceName,
   return_value_policy())
   .staticmethod("getDeviceName")
   ;
}

Following the guide here 
(http://wiki.python.org/moin/boost.python/PointersAndSmartPointers) I 
thought this was the right way but I get errors:


pyVideoInput.cpp
C:\boost_1_41_0\boost/python/object/make_instance.hpp(24) : error C2027: 
use of undefined type 'boost::STATIC_ASSERTION_FAILURE

'
   with
   [
   x=false
   ]
   C:\boost_1_41_0\boost/python/to_python_indirect.hpp(95) : see 
reference to function template instantiation 'PyObject *boos
t::python::objects::make_instance_impl::execute(Arg 
&)' being compiled

   with
   [
   T=char,
   Holder=holder_t,
   
Derived=boost::python::objects::make_ptr_instance,

   Arg=smart_pointer
   ]

..

   pyVideoInput.cpp(16) : see reference to function template 
instantiation 'boost::python::class_ &boost::python::class_>::def*)(int),boost::python::return_value_policy>(const 
char *,A1,const A2 &)' being comp

iled
   with
   [
   W=videoInput,
   ResultConverterGenerator=boost::python::manage_new_object,
   A1=char *(__cdecl *)(int),
   
A2=boost::python::return_value_policy

   ]


//

It seems to be attempting to use a smart_ptr?

Can anyone help explain this to me? Many thanks

Simon

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Conversion problem

2010-01-13 Thread Simon Pickles

Hello,

I wonder if someone could help me with a tricky conversion between c++ 
and python types (well, tricky for me!)


I have a c++ library that I would like to use in python via Boost::Python

One function fills a c++ unsigned char* buffer. It has two overloads:

   unsigned char * getPixels(int deviceID);
   bool getPixels(int id, unsigned char * pixels);

How would I go about getting that data into a python object, a string in 
particular? I seem to face several problems:

/
1) unsigned char* does not have a to_python converter to Py_String.

I tried this:

struct uchar_ptr_to_str
{
   static PyObject* convert(unsigned char* p)
   {
return incref( str(p).ptr());
   }
   static PyTypeObject const *get_pytype () {return &PyString_Type; }
};
struct uchar_to_str
{
   static PyObject* convert(unsigned char& p)
   {
return incref( str(p).ptr());
   }
   static PyTypeObject const *get_pytype () {return &PyString_Type; }
};

BOOST_PYTHON_MODULE(pyVideoInput)
{
   to_python_converter< unsigned char*, uchar_ptr_to_str, true >();   
   to_python_converter< unsigned char, uchar_to_str, true >();


   class_("videoInput")
  .def("getPixels", &videoInput::getPixels, 
return_value_policy())

  ;
}


/
2) How do I allocate memory in a python string and then pass the pointer 
through boost python, to be filled by the c++ function?


In c++, the library would be used like this:

   videoInput vi;
   
   unsigned char * buffer = new unsigned char[size];
   vi.getPixels(device, buffer);

The buffer could be pretty big so I want to pass by pointer, not by value

The alternative would be to use the overload which returns the pointer, 
but I can't get that to compile with bjam. I get the dreaded:


make_instance.hpp(24) : error C2027: 
use of undefined type 'boost::STATIC_ASSERTION_FAILURE


when I try to return a pointer...

Thanks for any help freeing me from my confusion!

Regards

Si





___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Conversion problem

2010-01-14 Thread Simon Pickles

Thanks Nicolas,

I learnt a lot from your way of doing it!

Simon

On 13/01/2010 11:17, Nicolas Lelong wrote:

Simon,

it seems that I wrapped the same videoinput library you're using.

I wrapped the getPixels the following way : python script is 
responsible of the memory allocation for pixels buffer (in a correctly 
sized string).


The getPixels function is wrapped as follows :

namespace {

  bool videoInput_getPixels(videoInput& input, int device_id, 
python::object memory_buffer)

  {
PyObject* pyObject = memory_buffer.ptr();
if (PyString_CheckExact(pyObject))
{
  Py_ssize_t string_size = PyString_Size(pyObject);
  if (string_size >= Py_ssize_t(input.getWidth(device_id)) * 
Py_ssize_t(input.getHeight(device_id)) * Py_ssize_t(3))

  {
unsigned char* pixels = reinterpret_castchar*>(PyString_AsString(pyObject));


return input.getPixels(device_id, pixels, false, false);
  }
}
return false;
  }

};

python::class_ klass("VideoInput");
klass.def("getPixels", videoInput_getPixels);

This certainly lacks some error checking for the actual 
'memory_buffer' parameter type, but can give you a clue.


HTH,

Nicolas

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig



___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig