From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14582 invoked by alias); 15 Jun 2009 20:50:06 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 14570 invoked by uid 22791); 15 Jun 2009 20:50:05 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4A36B3EE.8020102@redhat.com> Date: Mon, 15 Jun 2009 20:50:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: Tom Tromey CC: Thiago Jung Bauermann , Project Archer Subject: Re: [python][patch] Preserve string length, and embedded-nulls in pretty-print string emission. References: <4A1709CB.7030200@redhat.com> <4A1D8544.2030006@redhat.com> <4A240139.10001@redhat.com> <1243907642.9831.1.camel@hactar> <4A2CE878.7040002@redhat.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2009-q2/txt/msg00158.txt.bz2 On 06/11/2009 06:11 PM, Tom Tromey wrote: Hi Tom Thanks for the comments. Most are done, but I have some further questions with others. > 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... > Agreed, fixed. > Phil> + Py_DECREF (result); > > Set 'result = NULL' here. > Likewise > 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? > To avoid the use of an out-parameter? I can see the use of returning an encoded version of the the unicode PyObject string, but if you wanted that, why would you just not call: PyUnicode_AsEncodedString directly? Wouldn't the following: static PyObject* unicode_to_encoded_string (PyObject *unicode_str, const char *charset) { return PyUnicode_AsEncodedString (unicode_str, charset, NULL); } Be the same equivalent? What would the purpose of a new variant achieve there? > 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. > Similar to above, I'm not sure what you mean here. python_string_to_target_string does more than than the previous hunk comment, but eventually will have to be converted to char * to pass through the LA_PRINT_STRING that is directly below this code? > Phil> --- a/gdb/varobj.c > Phil> + Py_DECREF(py_str); > > Space before open paren. > > Fixed thanks! Regards Phil