Boost C++ Libraries: Ticket #3353: warning C4244: Py_ssize_t to unsigned int https://svn.boost.org/trac10/ticket/3353 <p> I am seeing a compiler warning regarding an unsafe type conversion: </p> <pre class="wiki">1&gt;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 </pre><p> Visual Studio 2005 </p> <p> Note that this may be a known issue or regression, as it was discussed 2 years ago here: <a class="ext-link" href="http://lists.boost.org/Archives/boost/2007/04/120377.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2007/04/120377.php</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3353 Trac 1.4.3 anonymous Tue, 23 Oct 2012 12:10:35 GMT <link>https://svn.boost.org/trac10/ticket/3353#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:1</guid> <description> <p> Hi, </p> <p> this is also an issue with visual studio 2010 x64. Is it ok to do....? </p> <p> diff -r 6c6ba1352fa2 boost/boost/python/detail/caller.hpp --- a/boost/boost/python/detail/caller.hpp Tue Oct 23 11:44:57 2012 </p> <blockquote> <p> +0200 </p> </blockquote> <p> +++ b/boost/boost/python/detail/caller.hpp Tue Oct 23 14:07:25 2012 </p> <blockquote> <p> +0200 </p> </blockquote> <p> @@ -50,7 +50,7 @@ </p> <blockquote> <p> return PyTuple_GET_ITEM(args_,N); </p> </blockquote> <blockquote> <p> } </p> </blockquote> <p> -inline unsigned arity(<a class="missing wiki">PyObject</a>* const&amp; args_) +inline Py_ssize_t arity(<a class="missing wiki">PyObject</a>* const&amp; args_) </p> <blockquote> <p> { </p> <blockquote> <p> return PyTuple_GET_SIZE(args_); </p> </blockquote> <p> } </p> </blockquote> <p> Chris </p> </description> <category>Ticket</category> </item> <item> <author>dominik.berner@…</author> <pubDate>Tue, 27 Jan 2015 07:55:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:2</guid> <description> <p> 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: </p> <pre class="wiki">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 &lt;class T&gt; - long count(T const&amp; value) const + ssize_t count(T const&amp; 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&amp; args_) +inline Py_ssize_t arity(PyObject* const&amp; 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&lt;&gt; - (PyInt_FromLong (Algorithms::size (c))))); + (PyInt_FromSsize_t (Algorithms::size (c))))); slice sl ((boost::python::handle&lt;&gt; </pre> </description> <category>Ticket</category> </item> <item> <author>teeks99@…</author> <pubDate>Tue, 12 May 2015 21:09:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:3</guid> <description> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <author>teeks99@…</author> <pubDate>Tue, 12 May 2015 21:11:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:3</guid> <description> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <author>dominik.berner@…</author> <pubDate>Wed, 13 May 2015 06:30:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:4</guid> <description> <p> 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) </p> <pre class="wiki">/// pyconfig.h #ifdef MS_WIN64 typedef __int64 ssize_t; #else typedef _W64 int ssize_t; #endif #define HAVE_SSIZE_T 1 </pre><p> If it's not there boost python does typedef int as ssize_t in boost/python/ssize_t.h </p> </description> <category>Ticket</category> </item> <item> <author>teeks99@…</author> <pubDate>Fri, 15 May 2015 15:34:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:5</guid> <description> <p> Ahh, cool, then I definitely like this solution better than <a class="new ticket" href="https://svn.boost.org/trac10/ticket/4596" title="#4596: Patches: Squash 64 bit warnings (new)">#4596</a>. </p> <p> I've created a pull request for your patch as <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/21" title="#21: Bugs: Can't compile transitive closure example (closed: Out of Date)">#21</a> on the github python tracker. </p> <p> I'm not sure where the slice_handler.hpp file is, I didn't see it anywhere in the boost master project, so I didn't include that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 21 Apr 2017 09:09:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:6</guid> <description> <p> The issue still exists in boost 1.63 using visual studio 2015 compiling for x64 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 03 Sep 2017 20:44:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3353#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3353#comment:7</guid> <description> <p> Issue still seems to exist on Boost 1.64 with VS 2017 (compiling x64). </p> </description> <category>Ticket</category> </item> </channel> </rss>