[C++-SIG] Py::String should be constructible from ptr and length

Barry Scott barry at scottb.demon.co.uk
Mon May 22 20:03:40 CEST 2000


These c'tor's have been in CXX for a while but did not make it into
the first cut of checkins to SourceForge. THe c'tor's have been on
SourceForge for a couple of weeks now.

However as you suggest I should use
std::string::size() and std::string::data() rather then c_str()
and the implied strlen() call.

These improvements have been committed to SourceForge.

		Barry


> -----Original Message-----
> From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> Behalf Of Steve Harris
> Sent: 18 May 2000 18:49
> To: c++-sig at python.org
> Subject: [C++-SIG] Py::String should be constructible from ptr and
> length
> 
> 
> At present, class Py::String can be constructed from a const char* or
> a const std::string&, but not from const char* and a size_t. We should
> have a version available that takes advantage of
> PyString_FromStringAndSize() by taking a length argument. This would
> allow construction from a non-null-terminated character array
> (especially a subset of such an array).
> 
> Also, the Py::String constructor taking a const std::string& as an
> argument should not use the c_str() function to call
> PyString_FromString(). Rather, it should call
> 
>   PyString_FromStringAndSize( str.data(), str.length() ) // or str.size()
> 
> since we've already gone through the trouble of figuring out the
> length of the contained string.
> 
> -- 
> Steven E. Harris
> Primus Knowledge Solutions, Inc.
> http://www.primus.com
> 
> _______________________________________________
> C++-SIG maillist  -  C++-SIG at python.org
> http://www.python.org/mailman/listinfo/c++-sig
> 




More information about the Cplusplus-sig mailing list