2015-01-20 16:07 GMT+01:00 Omer Katz <omer.d...@gmail.com>: > That's correct but can't we handle those cases in cppyy? > We should provide a native Python interface whenever it's possible. >
It's not possible to take a Python string as mutable reference. Here are some options that cppyy could implement: - Use bytearray, which is mutable. a = bytearray() e.SerializeToString(a) s = str(a) - Pass a list, and expect the function to append a (python) string l = [] e.SerializeToString(s) s = l[0] - Change the signature of the function so that it *returns* the string (like swig's OUTPUT <http://www.swig.org/Doc3.0/Arguments.html#Arguments_nn5>) result, s = e.SerializeToString() I don't know which method is the most convenient with cppyy. > > 2015-01-20 15:40 GMT+02:00 Amaury Forgeot d'Arc <amaur...@gmail.com>: > >> Hi, >> >> 2015-01-20 14:14 GMT+01:00 Omer Katz <omer.d...@gmail.com>: >> >>> The documentation is unclear how you can pass a pointer to a Python >>> variable e.g.: >>> str = "" >>> >>> e.SerializeToString(str) >>> >> >> Message::SerializeToString() updates its argument in-place, but Python >> strings are not mutable. >> You should allocate a std::string from Python code, and pass it to the >> function. >> Maybe something like: >> >> s = cppyy.gbl.std.string() >> e.SerializeToString(s) >> print s >> >> >> >> >>> >>> --------------------------------------------------------------------------- >>> TypeError Traceback (most recent call >>> last) >>> <ipython-input-7-993880892d74> in <module>() >>> ----> 1 e.SerializeToString(str) >>> >>> TypeError: none of the 5 overloaded methods succeeded. Full details: >>> bool google::protobuf::MessageLite::SerializeToString(std::string*) => >>> TypeError: cannot pass str as basic_string<char> >>> bool google::protobuf::MessageLite::SerializeToString(std::string*) => >>> TypeError: cannot pass str as basic_string<char> >>> bool google::protobuf::MessageLite::SerializeToString(std::string*) => >>> TypeError: cannot pass str as basic_string<char> >>> bool google::protobuf::MessageLite::SerializeToString(std::string*) => >>> TypeError: cannot pass str as basic_string<char> >>> bool google::protobuf::MessageLite::SerializeToString(std::string*) => >>> TypeError: cannot pass str as basic_string<char> >>> >>> Best Regards, >>> Omer Katz. >>> >>> _______________________________________________ >>> pypy-dev mailing list >>> pypy-dev@python.org >>> https://mail.python.org/mailman/listinfo/pypy-dev >>> >>> >> >> >> -- >> Amaury Forgeot d'Arc >> > -- Amaury Forgeot d'Arc
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev