Patchwork [pph] Fixing string streaming functions and their comments (issue4654076)

login
register
mail settings
Submitter Gab Charette
Date June 30, 2011, 1:37 a.m.
Message ID <20110630013756.4ED981C1480@gchare.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/102691/
State New
Headers show

Comments

Gab Charette - June 30, 2011, 1:37 a.m.
Some comments were wrong.

In particular, the strings read from the stream are placed in a data table, and thus the strings returned DO NOT need to be freed by the caller, they belong to the stream who handles them itself.

Also lto_output_string_with_length does handle NULL strings, removed the redundant logic.

Tested with bootstrap build and pph regression testing.

2011-06-29  Gabriel Charette  <gchare@google.com>

	* pph-streamer.h (struct pph_stream): Fix comment of data_in field.
	(pph_out_string_with_length): lto_output_string_with_length now handles
	NULL strings, call it directly.
	(pph_in_string): Fix comment.


--
This patch is available for review at http://codereview.appspot.com/4654076

Patch

diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h
index b899501..8d0c024 100644
--- a/gcc/cp/pph-streamer.h
+++ b/gcc/cp/pph-streamer.h
@@ -100,7 +100,7 @@  typedef struct pph_stream {
   struct lto_input_block *ib;
 
   /* String tables and other descriptors used by the LTO reading
-     routines.  NULL when the file is opened for reading.  */
+     routines.  NULL when the file is opened for writing.  */
   struct data_in *data_in;
 
   /* Array of sections in the PPH file.  */
@@ -250,21 +250,10 @@  static inline void
 pph_out_string_with_length (pph_stream *stream, const char *str,
 			       unsigned int len)
 {
-  if (str)
-    {
-      if (flag_pph_tracer >= 4)
-	pph_trace_string_with_length (stream, str, len);
-      lto_output_string_with_length (stream->ob, stream->ob->main_stream,
-				     str, len + 1, false);
-    }
-  else
-    {
-      /* lto_output_string_with_length does not handle NULL strings,
-	 but lto_output_string does.  */
-      if (flag_pph_tracer >= 4)
-	pph_trace_string (stream, str);
-      pph_out_string (stream, NULL);
-    }
+  if (flag_pph_tracer >= 4)
+    pph_trace_string_with_length (stream, str, len);
+  lto_output_string_with_length (stream->ob, stream->ob->main_stream,
+				  str, len + 1, false);
 }
 
 /* Output VEC V of ASTs to STREAM.
@@ -338,9 +327,7 @@  pph_in_bytes (pph_stream *stream, void *p, size_t n)
     pph_trace_bytes (stream, p, n);
 }
 
-/* Read and return a string of up to MAX characters from STREAM.
-   The caller is responsible for freeing the memory allocated
-   for the string.  */
+/* Read and return a string of up to MAX characters from STREAM.  */
 
 static inline const char *
 pph_in_string (pph_stream *stream)