diff options
author | Chih-Hung Hsieh <chh@google.com> | 2015-10-13 15:26:14 -0700 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2015-11-13 18:06:12 +0100 |
commit | b926e56b7ae5fc31aee3d4bb8f40906c9aa001c2 (patch) | |
tree | 4b6c69c6eafcd5e3673201e9e6401d4969fa5171 | |
parent | 3148f5cd3dafdce78a30b609901fc9b27cceb983 (diff) | |
download | elfutils-b926e56b7ae5fc31aee3d4bb8f40906c9aa001c2.tar.gz |
No nested function in dwarf_getscopevar to file scope.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
-rw-r--r-- | libdw/ChangeLog | 5 | ||||
-rw-r--r-- | libdw/dwarf_getscopevar.c | 39 |
2 files changed, 27 insertions, 17 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 99ec2e8c..fc044a2f 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2015-10-13 Chih-Hung Hsieh <chh@google.com> + + * dwarf_getscopevar.c (dwarf_getscopevar): Move nested + function 'file_matches' to file scope. + 2015-10-16 Mark Wielaard <mjw@redhat.com> * Makefile.am (libdw.so): Add -lz. diff --git a/libdw/dwarf_getscopevar.c b/libdw/dwarf_getscopevar.c index eb50c0ad..7b1416f3 100644 --- a/libdw/dwarf_getscopevar.c +++ b/libdw/dwarf_getscopevar.c @@ -52,6 +52,26 @@ getattr (Dwarf_Die *die, int search_name, Dwarf_Word *value) &attr_mem), value); } +static inline int +file_matches (const char *lastfile, + size_t match_file_len, const char *match_file, + Dwarf_Files *files, size_t idx, + bool *lastfile_matches) +{ + if (idx >= files->nfiles) + return false; + const char *file = files->info[idx].name; + if (file != lastfile) + { + size_t len = strlen (file); + *lastfile_matches = (len >= match_file_len + && !memcmp (match_file, file, match_file_len) + && (len == match_file_len + || file[len - match_file_len - 1] == '/')); + } + return *lastfile_matches; +} + /* Search SCOPES[0..NSCOPES-1] for a variable called NAME. Ignore the first SKIP_SHADOWS scopes that match the name. If MATCH_FILE is not null, accept only declaration in that source file; @@ -72,22 +92,6 @@ dwarf_getscopevar (Dwarf_Die *scopes, int nscopes, size_t match_file_len = match_file == NULL ? 0 : strlen (match_file); bool lastfile_matches = false; const char *lastfile = NULL; - inline bool file_matches (Dwarf_Files *files, size_t idx) - { - if (idx >= files->nfiles) - return false; - - const char *file = files->info[idx].name; - if (file != lastfile) - { - size_t len = strlen (file); - lastfile_matches = (len >= match_file_len - && !memcmp (match_file, file, match_file_len) - && (len == match_file_len - || file[len - match_file_len - 1] == '/')); - } - return lastfile_matches; - } /* Start with the innermost scope and move out. */ for (int out = 0; out < nscopes; ++out) @@ -130,7 +134,8 @@ dwarf_getscopevar (Dwarf_Die *scopes, int nscopes, || getfiles (&scopes[out], &files) != 0) break; - if (!file_matches (files, i)) + if (!file_matches (lastfile, match_file_len, match_file, + files, i, &lastfile_matches)) break; if (match_lineno > 0 |