This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: [python][patch] Preserve string length, and embedded-nulls in pretty-print string emission.
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> +unicode_to_encoded_string (PyObject *unicode_str, const char *charset, int *size)
[...]
Phil> + str_size = PyString_Size (string) + 1;
Phil> + result = xmemdup (PyString_AsString (string), str_size, str_size);
Phil> + if (size != NULL)
Phil> + *size = str_size;
How about a variant of this function that just returns the
intermediate 'string' PyObject?
Phil> + int is_string = 0;
Phil> - if (gdbpy_is_string (result))
Phil> - output = python_string_to_host_string (result);
Phil> - else if (PyObject_TypeCheck (result, &value_object_type))
Phil> + is_string = gdbpy_is_string (result);
Phil> + if (! is_string)
I think the previous code was clearer. Don't introduce is_string,
instead...
Phil> + Py_DECREF (result);
Set 'result = NULL' here.
Phil> + output = python_string_to_target_string (py_str, &len);
Phil> + if (output)
Phil> + {
Phil> + struct cleanup *old = make_cleanup (xfree, output);
Adding a new unicode_to_target_string variant (or
python_string_to_target_string, or whatever is nicest) means you can
avoid an allocation here.
Phil> --- a/gdb/varobj.c
Phil> + Py_DECREF(py_str);
Space before open paren.
Otherwise I think this is looking good. Thanks.
Tom