Message ID | CAO2gOZWCpm=p-cGRoAm5qa-J86h27WjGa=ngXoXnZ7w2KOZgGQ@mail.gmail.com |
---|---|
State | New |
Headers | show |
On Mon, Jul 14, 2014 at 1:40 PM, Dehao Chen <dehao@google.com> wrote: > This patch replaces getline with fgets so that gcc builts fine in darwin. Why not add getline to libiberty instead? This patch causes a huge stack usage. Thanks, Andrew Pinski > > Testing on going, ok for google-4_9 if test passes? > > Thanks, > Dehao > > Index: gcc/coverage.c > =================================================================== > --- gcc/coverage.c (revision 212523) > +++ gcc/coverage.c (working copy) > @@ -584,9 +584,9 @@ static void > reorder_module_groups (const char *imports_file, unsigned max_group) > { > FILE *f; > - int n, order = 0; > - size_t len; > - char *line = NULL; > + int order = 0; > + const int max_line_size = (1 << 16); > + char line[max_line_size]; > > module_name_tab.create (20); > > @@ -594,20 +594,23 @@ reorder_module_groups (const char *imports_file, u > if (!f) > error ("Can't open file %s", imports_file); > > - while ((n = getline (&line, &len, f)) != -1) > + while (fgets (line, max_line_size, f)) > { > + size_t n = strlen (line); > + gcc_assert (n < max_line_size - 1); > + if (line[n - 1] == '\n') > + line[n - 1] = '\0'; > + > module_name_entry **slot; > module_name_entry *m_e = XCNEW (module_name_entry); > > - line[n - 1] = '\0'; > - m_e->source_name = line; > + m_e->source_name = xstrdup (line); > m_e->order = order; > > slot = module_name_tab.find_slot (m_e, INSERT); > gcc_assert (!*slot); > *slot = m_e; > > - line = NULL; > order++; > }
On Mon, Jul 14, 2014 at 2:37 PM, Andrew Pinski <pinskia@gmail.com> wrote: > On Mon, Jul 14, 2014 at 1:40 PM, Dehao Chen <dehao@google.com> wrote: >> This patch replaces getline with fgets so that gcc builts fine in darwin. > > > Why not add getline to libiberty instead? This patch causes a huge stack usage. The callee is only called when a debug option (for developer) is turned on so the stack usage is not big concern. Longer term, we may want to add getline as you suggested. David > > Thanks, > Andrew Pinski > >> >> Testing on going, ok for google-4_9 if test passes? >> >> Thanks, >> Dehao >> >> Index: gcc/coverage.c >> =================================================================== >> --- gcc/coverage.c (revision 212523) >> +++ gcc/coverage.c (working copy) >> @@ -584,9 +584,9 @@ static void >> reorder_module_groups (const char *imports_file, unsigned max_group) >> { >> FILE *f; >> - int n, order = 0; >> - size_t len; >> - char *line = NULL; >> + int order = 0; >> + const int max_line_size = (1 << 16); >> + char line[max_line_size]; >> >> module_name_tab.create (20); >> >> @@ -594,20 +594,23 @@ reorder_module_groups (const char *imports_file, u >> if (!f) >> error ("Can't open file %s", imports_file); >> >> - while ((n = getline (&line, &len, f)) != -1) >> + while (fgets (line, max_line_size, f)) >> { >> + size_t n = strlen (line); >> + gcc_assert (n < max_line_size - 1); >> + if (line[n - 1] == '\n') >> + line[n - 1] = '\0'; >> + >> module_name_entry **slot; >> module_name_entry *m_e = XCNEW (module_name_entry); >> >> - line[n - 1] = '\0'; >> - m_e->source_name = line; >> + m_e->source_name = xstrdup (line); >> m_e->order = order; >> >> slot = module_name_tab.find_slot (m_e, INSERT); >> gcc_assert (!*slot); >> *slot = m_e; >> >> - line = NULL; >> order++; >> }
Index: gcc/coverage.c =================================================================== --- gcc/coverage.c (revision 212523) +++ gcc/coverage.c (working copy) @@ -584,9 +584,9 @@ static void reorder_module_groups (const char *imports_file, unsigned max_group) { FILE *f; - int n, order = 0; - size_t len; - char *line = NULL; + int order = 0; + const int max_line_size = (1 << 16); + char line[max_line_size]; module_name_tab.create (20); @@ -594,20 +594,23 @@ reorder_module_groups (const char *imports_file, u if (!f) error ("Can't open file %s", imports_file); - while ((n = getline (&line, &len, f)) != -1) + while (fgets (line, max_line_size, f)) { + size_t n = strlen (line); + gcc_assert (n < max_line_size - 1); + if (line[n - 1] == '\n') + line[n - 1] = '\0'; + module_name_entry **slot; module_name_entry *m_e = XCNEW (module_name_entry); - line[n - 1] = '\0'; - m_e->source_name = line; + m_e->source_name = xstrdup (line); m_e->order = order; slot = module_name_tab.find_slot (m_e, INSERT); gcc_assert (!*slot); *slot = m_e; - line = NULL; order++; }