Re: [patch][python] Implement Python lazy strings (PR 10705)

Phil Muldoon
2010-01-11T21:40:53Z

On 01/11/2010 09:30 PM, Phil Muldoon wrote:
> On 01/11/2010 09:08 PM, Tom Tromey wrote:
>>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>>
>> Phil> Index: gdb/varobj.c
>> [...]
>> Phil> + if (is_lazy_string (output))
>> Phil> + thevalue = extract_lazy_string (output, &type,
>> Phil> + &len, &encoding);
>> Phil> + else
>> Phil> {
>> Phil> - char *s = PyString_AsString (py_str);
>> Phil> - len = PyString_Size (py_str);
>> Phil> - thevalue = xmemdup (s, len + 1, len + 1);
>> Phil> - Py_DECREF (py_str);
>> Phil> + PyObject *py_str
>> Phil> + = python_string_to_target_python_string (output);
>> Phil> + if (py_str)
>> Phil> + {
>> Phil> + char *s = PyString_AsString (py_str);
>> Phil> + len = PyString_Size (py_str);
>> Phil> + thevalue = xmemdup (s, len + 1, len + 1);
>> Phil> + type = builtin_type (gdbarch)->builtin_char;
>> Phil> + Py_DECREF (py_str);
>> Phil> + }
>> Phil> }
>> Phil> Py_DECREF (output);
>> Phil> }
>> Phil> if (thevalue && !string_print)
>> Phil> {
>> Phil> do_cleanups (back_to);
>> Phil> + xfree (encoding);
>> Phil> return thevalue;
>>
>> This is wrong in the lazy string case, because you are returning raw
>> bytes, but the user expects them to be interpreted according to the
>> encoding.
>>
>> We discussed this on irc and I thought the result was that we agreed
>> that in this case we would pretend that a "string" hint was given.
>
> We did. This case is slightly different case from original case we
> discussed in irc (the original was in the non-mi case). Anyway, if
> thevalue is not NULL (and in these cases it won't) it is printed via
> LA_PRINT_STRING (just a few lines further past this patch hunk) and
> the encoding happens at that point.

Oops I spotted the bug just after I sent this. Everything will work if
only string_print is set properly for lazy strings ;) (which you
mentioned ;). Ok, sorry for the noise, I'll set that hint.