2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 05:42:30 +00:00

ssize_t patches merged from HEAD

[SVN r35327]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2006-09-26 00:48:44 +00:00
parent a824230155
commit 4eb286a034
9 changed files with 57 additions and 20 deletions

View File

@@ -3,6 +3,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python/str.hpp>
#include <boost/python/extract.hpp>
#include <boost/python/ssize_t.hpp>
namespace boost { namespace python { namespace detail {
@@ -21,10 +22,25 @@ str_base::str_base(const char* s)
: object(detail::new_reference(::PyString_FromString(s)))
{}
namespace {
ssize_t str_size_as_py_ssize_t(std::size_t n)
{
if (n > ssize_t_max)
{
throw std::range_error("str size > ssize_t_max");
}
return static_cast<ssize_t>(n);
}
} // namespace <anonymous>
str_base::str_base(char const* start, char const* finish)
: object(
detail::new_reference(
::PyString_FromStringAndSize(start, finish - start)
::PyString_FromStringAndSize(
start, str_size_as_py_ssize_t(finish - start)
)
)
)
{}
@@ -32,7 +48,9 @@ str_base::str_base(char const* start, char const* finish)
str_base::str_base(char const* start, std::size_t length) // new str
: object(
detail::new_reference(
::PyString_FromStringAndSize(start, length)
::PyString_FromStringAndSize(
start, str_size_as_py_ssize_t(length)
)
)
)
{}