Patchwork extern "C" fixes for sunCC

login
register
mail settings
Submitter Marc Glisse
Date Jan. 3, 2013, 4:12 p.m.
Message ID <alpine.DEB.2.02.1301031651190.3722@laptop-mg.saclay.inria.fr>
Download mbox | patch
Permalink /patch/209278/
State New
Headers show

Comments

Marc Glisse - Jan. 3, 2013, 4:12 p.m.
On Thu, 3 Jan 2013, Tom Tromey wrote:

>>>>>> "Marc" == Marc Glisse <marc.glisse@inria.fr> writes:
>
> Marc> libcpp/
> Marc> 	* line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.
>
> Yucky.

Yes, there is a discussion of what is necessary for a real fix (and an 
alternate hack) in the PR:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50177

Do you prefer an other approach?

> Marc>  	  line_map_realloc reallocator
> Marc> -	      = set->reallocator ? set->reallocator : xrealloc;
> Marc> +	      = set->reallocator ? set->reallocator
> Marc> +				 : (line_map_realloc) xrealloc;
>
> The indentation is wrong here, and it needs extra parens, per the GNU
> coding standards.
>
> I think it should have a comment as well.

Like this? (I'll test if approved, but I am not sure what was wrong with 
the indentation and parentheses so it may be wrong again)

Reformatting the patch, I noticed that I only fixed one of the 3 
occurences, so here are all 3.

 	* line-map.c (get_combined_adhoc_loc): Cast from extern "C" type.
 	(new_linemap): Likewise.
 	(linemap_enter_macro): Likewise.
Tom Tromey - Jan. 3, 2013, 5:27 p.m.
>>>>> "Marc" == Marc Glisse <marc.glisse@inria.fr> writes:

Marc> Do you prefer an other approach?

No, this is fine, just yucky.

Marc> Like this? (I'll test if approved, but I am not sure what was wrong
Marc> with the indentation and parentheses so it may be wrong again)

From the node 'Formatting' in the GCS:

       Insert extra parentheses so that Emacs will indent the code properly.
    For example, the following indentation looks nice if you do it by hand,

         v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
             + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;

    but Emacs would alter it.  Adding a set of parentheses produces
    something that looks equally nice, and which Emacs will preserve:

         v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
              + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);


The comments seem fine.
It is ok with the formatting fixed.

Tom

Patch

Index: line-map.c

===================================================================
--- line-map.c	(revision 194796)

+++ line-map.c	(working copy)

@@ -115,22 +115,24 @@  get_combined_adhoc_loc (struct line_maps

   lb.data = data;
   slot = (struct location_adhoc_data **)
       htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT);
   if (*slot == NULL)
     {
       if (set->location_adhoc_data_map.curr_loc >=
 	  set->location_adhoc_data_map.allocated)
 	{
 	  char *orig_data = (char *) set->location_adhoc_data_map.data;
 	  long long offset;
-	  line_map_realloc reallocator

-	      = set->reallocator ? set->reallocator : xrealloc;

+	  /* Cast away extern "C" from the type of xrealloc.  */

+	  line_map_realloc reallocator = set->reallocator

+					 ? set->reallocator

+					 : ((line_map_realloc) xrealloc);

 
 	  if (set->location_adhoc_data_map.allocated == 0)
 	    set->location_adhoc_data_map.allocated = 128;
 	  else
 	    set->location_adhoc_data_map.allocated *= 2;
 	  set->location_adhoc_data_map.data = (struct location_adhoc_data *)
 	      reallocator (set->location_adhoc_data_map.data,
 			   set->location_adhoc_data_map.allocated
 			   * sizeof (struct location_adhoc_data));
 	  offset = (char *) (set->location_adhoc_data_map.data) - orig_data;
@@ -210,22 +212,24 @@  new_linemap (struct line_maps *set,

   /* Depending on this variable, a macro map would be allocated in a
      different memory location than an ordinary map.  */
   bool macro_map_p = (reason == LC_ENTER_MACRO);
   struct line_map *result;
 
   if (LINEMAPS_USED (set, macro_map_p) == LINEMAPS_ALLOCATED (set, macro_map_p))
     {
       /* We ran out of allocated line maps. Let's allocate more.  */
       unsigned alloc_size;
 
-      line_map_realloc reallocator

-	= set->reallocator ? set->reallocator : xrealloc;

+      /* Cast away extern "C" from the type of xrealloc.  */

+      line_map_realloc reallocator = set->reallocator

+				     ? set->reallocator

+				     : ((line_map_realloc) xrealloc);

       line_map_round_alloc_size_func round_alloc_size =
 	set->round_alloc_size;
 
       /* We are going to execute some dance to try to reduce the
 	 overhead of the memory allocator, in case we are using the
 	 ggc-page.c one.
 	 
 	 The actual size of memory we are going to get back from the
 	 allocator is the smallest power of 2 that is greater than the
 	 size we requested.  So let's consider that size then.  */
@@ -423,22 +427,24 @@  linemap_tracks_macro_expansion_locs_p (s

    locations, this function returns NULL.  In that case, callers of
    this function cannot encode {line,column} pairs into locations of
    macro tokens anymore.  */
 
 const struct line_map *
 linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
 		     source_location expansion, unsigned int num_tokens)
 {
   struct line_map *map;
   source_location start_location;
-  line_map_realloc reallocator

-    = set->reallocator ? set->reallocator : xrealloc;

+  /* Cast away extern "C" from the type of xrealloc.  */

+  line_map_realloc reallocator = set->reallocator

+				 ? set->reallocator

+				 : ((line_map_realloc) xrealloc);

 
   start_location = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
 
   if (start_location <= set->highest_line
       || start_location > LINEMAPS_MACRO_LOWEST_LOCATION (set))
     /* We ran out of macro map space.   */
     return NULL;
 
   map = new_linemap (set, LC_ENTER_MACRO);