From 113fc7f1c3c24c1f84b90380acfa942e1a826412 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 30 Nov 2020 16:02:54 +0100 Subject: [PATCH] PyCXX: harmonize PyCXX with Python C API --- src/CXX/Python2/Objects.hxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/CXX/Python2/Objects.hxx b/src/CXX/Python2/Objects.hxx index 8351728247..664205dd81 100644 --- a/src/CXX/Python2/Objects.hxx +++ b/src/CXX/Python2/Objects.hxx @@ -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; @@ -1126,7 +1126,7 @@ namespace Py { protected: SeqBase& s; // the sequence - size_t offset; // item number + sequence_index_type offset; // item number T the_item; // lvalue public: @@ -1316,7 +1316,7 @@ namespace Py { public: // STL definitions - typedef size_t size_type; + typedef Py_ssize_t size_type; typedef seqref reference; typedef T const_reference; typedef seqref* pointer; @@ -2099,7 +2099,7 @@ namespace Py } else { - return std::string( PyString_AsString( ptr() ), static_cast( PyString_Size( ptr() ) ) ); + return std::string( PyString_AsString( ptr() ), static_cast( PyString_Size( ptr() ) ) ); } } @@ -2305,7 +2305,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 (); @@ -2363,7 +2363,7 @@ namespace Py { public: TupleN() - : Tuple( (sequence_index_type)0 ) + : Tuple( (size_type)0 ) { } @@ -2487,11 +2487,11 @@ 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(); - for (sequence_index_type i=0; i < size; i++) + for (size_type i=0; i < size; i++) { if(PyList_SetItem (ptr(), i, new_reference_to(Py::_None())) == -1) { @@ -2503,7 +2503,7 @@ namespace Py // List from a sequence List (const Sequence& s): Sequence() { - sequence_index_type n = s.length(); + size_type n = s.length(); set(PyList_New (n), true); validate(); for (sequence_index_type i=0; i < n; i++) @@ -2773,7 +2773,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 data_type; typedef std::pair< const T, T > value_type;