[pypy-dev] cppyy questions
Amaury Forgeot d'Arc
amauryfa at gmail.com
Tue Jan 20 16:49:24 CET 2015
2015-01-20 16:07 GMT+01:00 Omer Katz <omer.drow at 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 <amauryfa at gmail.com>:
>
>> Hi,
>>
>> 2015-01-20 14:14 GMT+01:00 Omer Katz <omer.drow at 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 at python.org
>>> https://mail.python.org/mailman/listinfo/pypy-dev
>>>
>>>
>>
>>
>> --
>> Amaury Forgeot d'Arc
>>
>
--
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150120/7bb4d0be/attachment.html>
More information about the pypy-dev
mailing list