Opened 13 years ago
Last modified 5 years ago
#3353 new Bugs
warning C4244: Py_ssize_t to unsigned int
Reported by: | Owned by: | Dave Abrahams | |
---|---|---|---|
Milestone: | Boost 1.40.0 | Component: | python USE GITHUB |
Version: | Boost 1.39.0 | Severity: | Problem |
Keywords: | Cc: |
Description
I am seeing a compiler warning regarding an unsafe type conversion:
1>c:\program files\boost\boost_1_39\boost\python\detail\caller.hpp(55) : warning C4244: 'return' : conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
Visual Studio 2005
Note that this may be a known issue or regression, as it was discussed 2 years ago here: http://lists.boost.org/Archives/boost/2007/04/120377.php
Change History (8)
comment:1 by , 10 years ago
comment:2 by , 8 years ago
It seems that it wasn't fixed until now (1.57.0) so I created a small patch to fix the compiler warnings generated by the Visual Studio 2013 compiler:
Index: Dependencies64/include/boost/python/list.hpp =================================================================== --- Dependencies64/include/boost/python/list.hpp (revision 29348) +++ Dependencies64/include/boost/python/list.hpp (revision 29350) @@ -73,7 +73,7 @@ } template <class T> - long count(T const& value) const + ssize_t count(T const& value) const { return base::count(object(value)); } Index: Dependencies64/include/boost/python/detail/caller.hpp =================================================================== --- Dependencies64/include/boost/python/detail/caller.hpp (revision 29348) +++ Dependencies64/include/boost/python/detail/caller.hpp (revision 29350) @@ -50,7 +50,7 @@ return PyTuple_GET_ITEM(args_,N); } -inline unsigned arity(PyObject* const& args_) +inline Py_ssize_t arity(PyObject* const& args_) { return PyTuple_GET_SIZE(args_); } Index: Dependencies64/include/indexing_suite/slice_handler.hpp =================================================================== --- Dependencies64/include/indexing_suite/slice_handler.hpp (revision 29348) +++ Dependencies64/include/indexing_suite/slice_handler.hpp (revision 29350) @@ -286,7 +286,7 @@ boost::python::object length ((boost::python::handle<> - (PyInt_FromLong (Algorithms::size (c))))); + (PyInt_FromSsize_t (Algorithms::size (c))))); slice sl ((boost::python::handle<>
comment:3 by , 7 years ago
I like the solution of actually using the ssize_t instead of casting (down on 64 bit?) to a long/unsigned, however, I don't think that is defined on windows. Is this the same as ptrdiff_t? Does boost have a solution for this somewhere?
comment:3 by , 7 years ago
I like the solution of actually using the ssize_t instead of casting (down on 64 bit?) to a long/unsigned, however, I don't think that is defined on windows. Is this the same as ptrdiff_t? Does boost have a solution for this somewhere?
comment:4 by , 7 years ago
That's right ssize_t is not defined for MSVC by default, however Python 2.7.x does define it in pyconfig.h which is used by boost python. the define is around ln 198 in pyconfig.h (2.7.4)
/// pyconfig.h #ifdef MS_WIN64 typedef __int64 ssize_t; #else typedef _W64 int ssize_t; #endif #define HAVE_SSIZE_T 1
If it's not there boost python does typedef int as ssize_t in boost/python/ssize_t.h
comment:5 by , 7 years ago
comment:6 by , 6 years ago
The issue still exists in boost 1.63 using visual studio 2015 compiling for x64
Hi,
this is also an issue with visual studio 2010 x64. Is it ok to do....?
diff -r 6c6ba1352fa2 boost/boost/python/detail/caller.hpp --- a/boost/boost/python/detail/caller.hpp Tue Oct 23 11:44:57 2012
+++ b/boost/boost/python/detail/caller.hpp Tue Oct 23 14:07:25 2012
@@ -50,7 +50,7 @@
-inline unsigned arity(PyObject* const& args_) +inline Py_ssize_t arity(PyObject* const& args_)
Chris