Ignore:
Timestamp:
Sep 15, 2006, 7:09:38 AM (19 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/variable.c

    r431 r503  
    11/* Internals of variables for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
    3 2002 Free Software Foundation, Inc.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    45This file is part of GNU Make.
    56
    6 GNU Make is free software; you can redistribute it and/or modify
    7 it under the terms of the GNU General Public License as published by
    8 the Free Software Foundation; either version 2, or (at your option)
    9 any later version.
    10 
    11 GNU Make is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Make; see the file COPYING.  If not, write to
    18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    19 Boston, MA 02111-1307, USA.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    2018
    2119#include "make.h"
     20
     21#include <assert.h>
     22
    2223#include "dep.h"
    2324#include "filedef.h"
     
    618619initialize_file_variables (struct file *file, int reading)
    619620{
    620   register struct variable_set_list *l = file->variables;
     621  struct variable_set_list *l = file->variables;
    621622
    622623  if (l == 0)
     
    714715   and free all its storage.  */
    715716
    716 static void
    717 free_variable_name_and_value (const void *item)
    718 {
    719   struct variable *v = (struct variable *) item;
    720   free (v->name);
    721   free (v->value);
    722 }
    723 
    724 void
    725 pop_variable_scope (void)
    726 {
    727   struct variable_set_list *setlist = current_variable_set_list;
    728   struct variable_set *set = setlist->set;
    729 
    730   current_variable_set_list = setlist->next;
    731   free ((char *) setlist);
    732 
    733   hash_map (&set->table, free_variable_name_and_value);
    734   hash_free (&set->table, 1);
    735 
    736   free ((char *) set);
    737 }
    738 
    739717struct variable_set_list *
    740718create_new_variable_set (void)
     
    755733}
    756734
    757 /* Create a new variable set and push it on the current setlist.  */
     735static void
     736free_variable_name_and_value (const void *item)
     737{
     738  struct variable *v = (struct variable *) item;
     739  free (v->name);
     740  free (v->value);
     741}
     742
     743void
     744free_variable_set (struct variable_set_list *list)
     745{
     746  hash_map (&list->set->table, free_variable_name_and_value);
     747  hash_free (&list->set->table, 1);
     748  free ((char *) list->set);
     749  free ((char *) list);
     750}
     751
     752/* Create a new variable set and push it on the current setlist.
     753   If we're pushing a global scope (that is, the current scope is the global
     754   scope) then we need to "push" it the other way: file variable sets point
     755   directly to the global_setlist so we need to replace that with the new one.
     756 */
    758757
    759758struct variable_set_list *
    760759push_new_variable_scope (void)
    761760{
    762   return (current_variable_set_list = create_new_variable_set());
     761  current_variable_set_list = create_new_variable_set();
     762  if (current_variable_set_list->next == &global_setlist)
     763    {
     764      /* It was the global, so instead of new -> &global we want to replace
     765         &global with the new one and have &global -> new, with current still
     766         pointing to &global  */
     767      struct variable_set *set = current_variable_set_list->set;
     768      current_variable_set_list->set = global_setlist.set;
     769      global_setlist.set = set;
     770      current_variable_set_list->next = global_setlist.next;
     771      global_setlist.next = current_variable_set_list;
     772      current_variable_set_list = &global_setlist;
     773    }
     774  return (current_variable_set_list);
     775}
     776
     777void
     778pop_variable_scope (void)
     779{
     780  struct variable_set_list *setlist;
     781  struct variable_set *set;
     782
     783  /* Can't call this if there's no scope to pop!  */
     784  assert(current_variable_set_list->next != NULL);
     785
     786  if (current_variable_set_list != &global_setlist)
     787    {
     788      /* We're not pointing to the global setlist, so pop this one.  */
     789      setlist = current_variable_set_list;
     790      set = setlist->set;
     791      current_variable_set_list = setlist->next;
     792    }
     793  else
     794    {
     795      /* This set is the one in the global_setlist, but there is another global
     796         set beyond that.  We want to copy that set to global_setlist, then
     797         delete what used to be in global_setlist.  */
     798      setlist = global_setlist.next;
     799      set = global_setlist.set;
     800      global_setlist.set = setlist->set;
     801      global_setlist.next = setlist->next;
     802    }
     803
     804  /* Free the one we no longer need.  */
     805  free ((char *) setlist);
     806  hash_map (&set->table, free_variable_name_and_value);
     807  hash_free (&set->table, 1);
     808  free ((char *) set);
    763809}
    764810
     
    796842                          struct variable_set_list *setlist1)
    797843{
    798   register struct variable_set_list *list0 = *setlist0;
     844  struct variable_set_list *to = *setlist0;
    799845  struct variable_set_list *last0 = 0;
    800846
    801   while (setlist1 != 0 && list0 != 0)
    802     {
    803       struct variable_set_list *next = setlist1;
    804       setlist1 = setlist1->next;
    805 
    806       merge_variable_sets (list0->set, next->set);
    807 
    808       last0 = list0;
    809       list0 = list0->next;
    810     }
    811 
    812   if (setlist1 != 0)
     847  /* If there's nothing to merge, stop now.  */
     848  if (!setlist1)
     849    return;
     850
     851  /* This loop relies on the fact that all setlists terminate with the global
     852     setlist (before NULL).  If that's not true, arguably we SHOULD die.  */
     853  if (to)
     854    while (setlist1 != &global_setlist && to != &global_setlist)
     855      {
     856        struct variable_set_list *from = setlist1;
     857        setlist1 = setlist1->next;
     858
     859        merge_variable_sets (to->set, from->set);
     860
     861        last0 = to;
     862        to = to->next;
     863      }
     864
     865  if (setlist1 != &global_setlist)
    813866    {
    814867      if (last0 == 0)
     
    13101363#endif /* __MSDOS__ */
    13111364#ifdef WINDOWS32
    1312   if ((origin == o_file || origin == o_override) && streq (varname, "SHELL"))
     1365  if ((origin == o_file || origin == o_override || origin == o_command)
     1366      && streq (varname, "SHELL"))
    13131367    {
    13141368      extern char *default_shell;
Note: See TracChangeset for help on using the changeset viewer.