[pygccxml-commit] SF.net SVN: pygccxml: [1032] pyplusplus_dev/pyplusplus/code_repository/ convenien
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-05-05 19:18:20
|
Revision: 1032 http://svn.sourceforge.net/pygccxml/?rev=1032&view=rev Author: roman_yakovenko Date: 2007-05-05 12:18:21 -0700 (Sat, 05 May 2007) Log Message: ----------- removing dependency on boost::python::len function Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/convenience.py Modified: pyplusplus_dev/pyplusplus/code_repository/convenience.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/convenience.py 2007-05-04 13:31:21 UTC (rev 1031) +++ pyplusplus_dev/pyplusplus/code_repository/convenience.py 2007-05-05 19:18:21 UTC (rev 1032) @@ -35,15 +35,21 @@ boost::python::throw_error_already_set(); } -inline void -ensure_sequence( boost::python::object seq, index_type expected_length=-1 ){ - PyObject* seq_impl = seq.ptr(); - - if( !PySequence_Check( seq_impl ) ){ +inline index_type sequence_len(boost::python::object const& obj){ + if( !PySequence_Check( obj.ptr() ) ){ raise_error( PyExc_TypeError, "Sequence expected" ); } - index_type length = PySequence_Length( seq_impl ); + index_type result = PyObject_Length( obj.ptr() ); + if( PyErr_Occurred() ){ + boost::python::throw_error_already_set(); + } + return result; +} + +inline void +ensure_sequence( boost::python::object seq, index_type expected_length=-1 ){ + index_type length = sequence_len( seq ); if( expected_length != -1 && length != expected_length ){ std::stringstream err; err << "Expected sequence length is " << expected_length << ". " @@ -56,7 +62,7 @@ void ensure_uniform_sequence( boost::python::object seq, index_type expected_length=-1 ){ ensure_sequence( seq, expected_length ); - index_type length = boost::python::len( seq ); + index_type length = sequence_len( seq ); for( index_type index = 0; index < length; ++index ){ boost::python::object item = seq[index]; @@ -86,7 +92,7 @@ template< class Inserter > void copy_sequence( boost::python::object const& seq, Inserter inserter ){ - index_type length = boost::python::len( seq ); + index_type length = sequence_len( seq ); for( index_type index = 0; index < length; ++index ){ inserter = seq[index]; } @@ -94,7 +100,7 @@ template< class Inserter, class TItemType > void copy_sequence( boost::python::object const& seq, Inserter inserter, boost::type< TItemType > ){ - index_type length = boost::python::len( seq ); + index_type length = sequence_len( seq ); for( index_type index = 0; index < length; ++index ){ boost::python::object item = seq[index]; inserter = boost::python::extract< TItemType >( item ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |