[C++-sig] boost.python: no overflow checking for unsigned int parameters ?

2009-06-15 Thread Anderson Lizardo
Hi,

I noticed that boost.python silently accepts negative (or too long)
integers for constructor/methods that have "unsigned int" parameters.
(signed) "int" arguments seem to be handled just fine. Is it possible
to tell boost.python to check for overflow and raise an exception just
like it happens to int parameters ?

BTW, I'm using boost1.38.

See test case below (save it as "mymodule.cpp"), "MyClass1" uses int
parameters, "MyClass2" uses unsigned int:

### snip ###

/*

$ g++ -shared -I/usr/include/python2.6 -o mymodule.so mymodule.cpp
-lboost_python-mt
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mymodule import MyClass1, MyClass2
>>>
>>> MyClass1(840835495615213080).some_method(840835495615213080)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int
>>>
>>> MyClass1(-1).some_method(-1)
MyClass1: -1
MyClass1::some_method: -1
>>>
>>> MyClass2(840835495615213080).some_method(840835495615213080)
MyClass2: 4294967295
MyClass2::some_method: 4294967295
>>>
>>> MyClass2(-1).some_method(-1)
MyClass2: 4294967295
MyClass2::some_method: 4294967295
>>>

*/

#include 
#include 

class MyClass1
{
public:
MyClass1(int x) { std::cout << "MyClass1: " << x << std::endl; }
void some_method(int x) { std::cout << "MyClass1::some_method: " << x
<< std::endl; }
};

class MyClass2
{
public:
MyClass2(unsigned int x) { std::cout << "MyClass2: " << x << std::endl; 
}
void some_method(unsigned int x) { std::cout <<
"MyClass2::some_method: " << x << std::endl; }
};

using namespace boost::python;

BOOST_PYTHON_MODULE(mymodule)
{
class_("MyClass1", init())
.def("some_method", &MyClass1::some_method)
;
class_("MyClass2", init())
.def("some_method", &MyClass2::some_method)
;
}

### snip ###

Regards,
-- 
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
___
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


Re: [C++-sig] boost.python: no overflow checking for unsigned int parameters ?

2009-06-15 Thread Ralf W. Grosse-Kunstleve

If you send me a patch (against the boost trunk) I'll test it and check it in.
Probably, the file to be changed is
  boost/libs/python/src/converter/builtin_converters.cpp
I'd try working with
  boost/numeric/conversion/cast.hpp
Ralf



- Original Message 

From: Anderson Lizardo 
To: [email protected]
Sent: Monday, June 15, 2009 12:24:29 PM
Subject: [C++-sig] boost.python: no overflow checking for unsigned int 
parameters ?

Hi,

I noticed that boost.python silently accepts negative (or too long)
integers for constructor/methods that have "unsigned int" parameters.
(signed) "int" arguments seem to be handled just fine. Is it possible
to tell boost.python to check for overflow and raise an exception just
like it happens to int parameters ?

BTW, I'm using boost1.38.

See test case below (save it as "mymodule.cpp"), "MyClass1" uses int
parameters, "MyClass2" uses unsigned int:

### snip ###

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


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

2009-06-15 Thread Renato Araujo
Hi Simon,

Did you export your class ResourceManager to python? If this class not
is copyable you can export with some like that:

class_("ClassName")

BR
Renato



On Mon, Jun 15, 2009 at 5:05 PM, Simon Pickles wrote:
> 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
>



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


[C++-sig] boost.python build failure on Mac

2009-06-15 Thread Gerald Iakobinyi-Pich


Hello,

I am facing an error when trying to build boost.python. I hope I am in  
the right place to address this issue. If not please redirect me ...


So first I ran bootstrap.sh in my boost root dir pro:boost_1_39_0, and  
that is the output:


-n Building Boost.Jam with toolset darwin...
tools/jam/src/bin.macosxx86/bjam
-n Detecting Python version...
2.6
-n Detecting Python root...
/Library/Frameworks/Python.framework/Versions/2.6
-n Unicode/ICU support for Boost.Regex?...
not found.
Backing up existing Boost.Build configuration in project-config.jam.4
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

./bjam

To adjust configuration, edit 'project-config.jam'.
Further information:

   - Command line help:
 ./bjam --help

   - Getting started guide:
 http://www.boost.org/more/getting_started/unix-variants.html

   - Boost.Build documentation:
 http://www.boost.org/boost-build2/doc/html/index.html



No I tried to build the 'quickstart' example, and the linker seems to  
enter some kind of 'endless' loop. Building extending.so, never comes  
to an end:


darwin.compile.c++ /Users/nutrina/temp/boost/bin.v2/libs/python/build/ 
darwin-4.0.1/debug/import.o
darwin.compile.c++ /Users/nutrina/temp/boost/bin.v2/libs/python/build/ 
darwin-4.0.1/debug/exec.o
darwin.compile.c++ /Users/nutrina/temp/boost/bin.v2/libs/python/build/ 
darwin-4.0.1/debug/object/function_doc_signature.o
darwin.link.dll /Users/nutrina/temp/boost/bin.v2/libs/python/build/ 
darwin-4.0.1/debug/libboost_python-xgcc40-d-1_39.dylib
darwin.link.dll /Users/nutrina/temp/boost-python-quickstart/ 
darwin-4.0.1/debug/extending.so




Has somebody else encountered the same error? Could somebody give some  
hint? Btw. I am using XCode 3.1.2 + the toolset it comes with (i686- 
apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)).


Thanks,
Gerald










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


Re: [C++-sig] Fw: g++ compiler limitations other than -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?

2009-06-15 Thread Stefan Seefeld

On 06/11/2009 08:13 PM, Christopher A Mejia wrote:

Stefan / cplusplus-sig,

Based on Stefan's encouragement, I developed a minimal complete test case


Thanks ! Can you please submit that as an issue on 
https://svn.boost.org/trac/boost/ ? We may then follow-up there...


Stefan


--

  ...ich hab' noch einen Koffer in Berlin...

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


Re: [C++-sig] Fw: g++ compiler limitations otherthan -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?

2009-06-15 Thread Christopher A Mejia

Stefan,

OK--it's in the system as #3183.  Thanks again for your help, and anyone 
should feel free to let me know if they need more information about this 
issue.


--Chris

- Original Message - 
From: Stefan Seefeld

To: Development of Python/C++ integration
Sent: Monday, June 15, 2009 3:00 PM
Subject: Re: [C++-sig] Fw: g++ compiler limitations 
otherthan -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?



On 06/11/2009 08:13 PM, Christopher A Mejia wrote:

Stefan / cplusplus-sig,

Based on Stefan's encouragement, I developed a minimal complete test case


Thanks ! Can you please submit that as an issue on
https://svn.boost.org/trac/boost/ ? We may then follow-up there...

Stefan


--

  ...ich hab' noch einen Koffer in Berlin... 


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