PyCXX: harmonize PyCXX with Python C API
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
|
||||
namespace Py
|
||||
{
|
||||
typedef size_t sequence_index_type; // type of an index into a sequence
|
||||
typedef Py_ssize_t sequence_index_type; // type of an index into a sequence
|
||||
|
||||
// Forward declarations
|
||||
class Object;
|
||||
@@ -1095,7 +1095,7 @@ namespace Py
|
||||
{
|
||||
protected:
|
||||
SeqBase<T> &s; // the sequence
|
||||
size_t offset; // item number
|
||||
sequence_index_type offset; // item number
|
||||
T the_item; // lvalue
|
||||
|
||||
public:
|
||||
@@ -1289,7 +1289,7 @@ namespace Py
|
||||
{
|
||||
public:
|
||||
// STL definitions
|
||||
typedef size_t size_type;
|
||||
typedef Py_ssize_t size_type;
|
||||
typedef seqref<T> reference;
|
||||
typedef T const_reference;
|
||||
typedef seqref<T> *pointer;
|
||||
@@ -1298,7 +1298,8 @@ namespace Py
|
||||
|
||||
virtual size_type max_size() const
|
||||
{
|
||||
return std::string::npos; // ?
|
||||
//return std::string::npos; // ?
|
||||
return std::numeric_limits<size_type>::max();
|
||||
}
|
||||
|
||||
virtual size_type capacity() const
|
||||
@@ -1822,7 +1823,7 @@ namespace Py
|
||||
// Assignment from C string
|
||||
Byte &operator=( const std::string &v )
|
||||
{
|
||||
set( PyBytes_FromStringAndSize( const_cast<char*>( v.c_str() ),1 ), true );
|
||||
set( PyBytes_FromStringAndSize( const_cast<char*>( v.c_str() ), 1 ), true );
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1869,13 +1870,13 @@ namespace Py
|
||||
}
|
||||
|
||||
Bytes( const std::string &v )
|
||||
: SeqBase<Byte>( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), static_cast<int>( v.length() ) ), true )
|
||||
: SeqBase<Byte>( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), v.length() ), true )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
Bytes( const std::string &v, Py_ssize_t vsize )
|
||||
: SeqBase<Byte>( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), static_cast<int>( vsize ) ), true )
|
||||
: SeqBase<Byte>( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), vsize ), true )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
@@ -1908,7 +1909,7 @@ namespace Py
|
||||
// Assignment from C string
|
||||
Bytes &operator=( const std::string &v )
|
||||
{
|
||||
set( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), static_cast<int>( v.length() ) ), true );
|
||||
set( PyBytes_FromStringAndSize( const_cast<char*>( v.data() ), v.length() ), true );
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1917,7 +1918,7 @@ namespace Py
|
||||
// Queries
|
||||
virtual size_type size() const
|
||||
{
|
||||
return static_cast<size_type>( PyBytes_Size( ptr() ) );
|
||||
return PyBytes_Size( ptr() );
|
||||
}
|
||||
|
||||
operator std::string() const
|
||||
@@ -1927,7 +1928,7 @@ namespace Py
|
||||
|
||||
std::string as_std_string() const
|
||||
{
|
||||
return std::string( PyBytes_AsString( ptr() ), static_cast<size_type>( PyBytes_Size( ptr() ) ) );
|
||||
return std::string( PyBytes_AsString( ptr() ), static_cast<size_t>( PyBytes_Size( ptr() ) ) );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2112,7 +2113,7 @@ namespace Py
|
||||
|
||||
String &operator=( const unicodestring &v )
|
||||
{
|
||||
set( PyUnicode_FromUnicode( const_cast<Py_UNICODE *>( v.data() ), static_cast<int>( v.length() ) ), true );
|
||||
set( PyUnicode_FromUnicode( const_cast<Py_UNICODE *>( v.data() ), v.length() ), true );
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -2125,12 +2126,12 @@ namespace Py
|
||||
// Queries
|
||||
virtual size_type size() const
|
||||
{
|
||||
return static_cast<size_type>( PyUnicode_GET_SIZE( ptr() ) );
|
||||
return PyUnicode_GET_SIZE( ptr() );
|
||||
}
|
||||
|
||||
unicodestring as_unicodestring() const
|
||||
{
|
||||
return unicodestring( PyUnicode_AS_UNICODE( ptr() ), static_cast<size_type>( PyUnicode_GET_SIZE( ptr() ) ) );
|
||||
return unicodestring( PyUnicode_AS_UNICODE( ptr() ), PyUnicode_GET_SIZE( ptr() ) );
|
||||
}
|
||||
|
||||
operator std::string() const
|
||||
@@ -2179,7 +2180,7 @@ namespace Py
|
||||
}
|
||||
|
||||
// New tuple of a given size
|
||||
explicit Tuple( sequence_index_type size = 0 )
|
||||
explicit Tuple( size_type size=0 )
|
||||
{
|
||||
set( PyTuple_New( size ), true );
|
||||
validate();
|
||||
@@ -2198,7 +2199,7 @@ namespace Py
|
||||
|
||||
set( PyTuple_New( limit ), true );
|
||||
validate();
|
||||
|
||||
|
||||
for( sequence_index_type i=0; i < limit; i++ )
|
||||
{
|
||||
if( PyTuple_SetItem( ptr(), i, new_reference_to( s[i] ) ) == -1 )
|
||||
@@ -2237,7 +2238,7 @@ namespace Py
|
||||
{
|
||||
public:
|
||||
TupleN()
|
||||
: Tuple( (sequence_index_type)0 )
|
||||
: Tuple( (size_type)0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2362,7 +2363,7 @@ namespace Py
|
||||
validate();
|
||||
}
|
||||
// Creation at a fixed size
|
||||
List( sequence_index_type size = 0 )
|
||||
List( size_type size = 0 )
|
||||
{
|
||||
set( PyList_New( size ), true );
|
||||
validate();
|
||||
@@ -2379,7 +2380,7 @@ namespace Py
|
||||
List( const Sequence &s )
|
||||
: Sequence()
|
||||
{
|
||||
sequence_index_type n =( int )s.length();
|
||||
size_type n = s.length();
|
||||
set( PyList_New( n ), true );
|
||||
validate();
|
||||
for( sequence_index_type i=0; i < n; i++ )
|
||||
@@ -2659,7 +2660,7 @@ namespace Py
|
||||
// If you assume that Python mapping is a hash_map...
|
||||
// hash_map::value_type is not assignable, but
|
||||
//( *it ).second = data must be a valid expression
|
||||
typedef size_t size_type;
|
||||
typedef Py_ssize_t size_type;
|
||||
typedef Object key_type;
|
||||
typedef mapref<T> data_type;
|
||||
typedef std::pair< const T, T > value_type;
|
||||
|
||||
Reference in New Issue
Block a user