[C++-sig] [c++-sig] python std::string assignment

Furkan Kuru furkankuru at gmail.com
Fri Oct 17 13:10:23 CEST 2008


class DataPack {

    std::string name;

        class_<DataPack >("DataPack ")
                   .def_readwrite("name", &DataPack ::name);

in my py file:

d = Data.DataPack()
d.name = "123456789101234567891012345678910"

It works fine in xp but breaks application down in a vista installed
computer memory corrupt
if I set shorter string:  d.name = "123" it is fine for vista too.
= operator does not work as it does in c++ side, I think.

On Fri, Oct 17, 2008 at 1:54 PM, Stefan Seefeld <seefeld at sympatico.ca>wrote:

> Furkan Kuru wrote:
>> Hello,
>> I have exported a struct containing a std::string field and used it one of
>> my py files.
>> I used same py and pyd file in another operating system (vista).
>> It just stuck without giving any errors.
>> I figured out that the std::string field gets a limited space (as it
>> should do)
>> but does not increase it when initialized or assigned with longer sequence
>> of characters.
>> Is it a "quick and good" solution to write a wrapper for std::string and
>> set its reserved space a high number ( reserve(128); )
>> or
>> export overloaded = operator to python side?
> Sorry, but it isn't clear at all what problem you are seeing. Can you
> provide a concise description of what behavior you expect, and what you
> actually get (together with a minimal but complete code snippet) ? In that
> case someone on this list may be able to help you.
> Thanks,
>      Stefan
> --
>     ...ich hab' noch einen Koffer in Berlin...
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig

Furkan Kuru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081017/87124532/attachment.htm>

More information about the Cplusplus-sig mailing list