[PATCH v3 headers] variable uglification

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Sun Sep 19 08:51:00 GMT 2010


Hi Paolo, all,

I noticed that C++ header uglification seems to be a slow manual
process.  That looks suboptimal, and shouldn't be the case, it
should be mostly automatic and quick (in terms of developer time).

My first idea was to just hunt the headers for suspicious words
(avoiding the use of the preprocessor to catch all possible code):

cd libstdc++-v3
set x `find include \( -name \*.cc -o -name \*.am -o -name \*.in \) \
            -prune -o -type f -print`
shift
perl -e '
  my %words;
  undef $/;             # slurp whole file at once, for multiline match
  while (<>) {
    s/\/\/[^\n]*//g;    # good enough for C++ comments
    s/\/\*.*?\*\///gs;  # good enough for C comments
    foreach my $word (split /\b/) {
      $words{$word}++
        if $word =~ m/^[a-zA-Z][a-zA-Z0-9_]*$/; # ignore _words
    }
  }
  foreach my $word (keys %words) {
    print "$words{$word}\t$word\n";
  }' "$@" |
sort -k1n | less

which already shows lots of potential issues below ext/, but also false
positives from preprocessor statements, string literals, arithmetic
constant prefixes and suffixes.  Also, I still have to generate a list
of keywords and C++ API words to exclude, but glancing over them is
fairly easy.

My next idea would be to instantiate as much code as possible and
extract debugging symbols, maybe that can be an easy second attack
vector.

Another idea would be a testsuite addition poisoning one- and
two-character identifiers not part of the API?  Might be too dangerous
in the presence of broken system headers.

Who designed C++ classes inside <random> with multiple one-character
member names in the API by the way?

Anyway, I found a couple of instances with the above approach, patch
below survived bootstrap and regtest on x86_64-unknown-linux-gnu.  OK?

Thanks,
Ralf

Uglify C++ headers some more.

libstdc++-v3/ChangeLog:
2010-09-19  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	* include/ext/throw_allocator.h
	(hash<__gnu_cxx::throw_value_limit>::operator()): Uglify local.
	(hash<__gnu_cxx::throw_value_random>::operator()): Likewise.
	* include/parallel/set_operations.h (__symmetric_difference_func):
	Uglify remaining arguments to __count, __first_empty, _M_invoke.
	(__difference_func): Likewise for __count.
	* include/profile/impl/profiler_node.h
	(__object_info_base::__write): Uglify parameter.

diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h
index 669d433..cc34478 100644
--- a/libstdc++-v3/include/ext/throw_allocator.h
+++ b/libstdc++-v3/include/ext/throw_allocator.h
@@ -737,8 +737,8 @@ namespace std
       size_t
       operator()(const __gnu_cxx::throw_value_limit& __val) const
       {
-	std::hash<std::size_t> h;
-	size_t __result = h(__val._M_i);
+	std::hash<std::size_t> __h;
+	size_t __result = __h(__val._M_i);
 	return __result;
       }
     };
@@ -751,8 +751,8 @@ namespace std
       size_t
       operator()(const __gnu_cxx::throw_value_random& __val) const
       {
-	std::hash<std::size_t> h;
-	size_t __result = h(__val._M_i);
+	std::hash<std::size_t> __h;
+	size_t __result = __h(__val._M_i);
 	return __result;
       }
     };
diff --git a/libstdc++-v3/include/parallel/set_operations.h b/libstdc++-v3/include/parallel/set_operations.h
index f6b076f..f552c1d 100644
--- a/libstdc++-v3/include/parallel/set_operations.h
+++ b/libstdc++-v3/include/parallel/set_operations.h
@@ -103,11 +103,11 @@ namespace __gnu_parallel
       }
 
       _DifferenceType
-      __count(_IIter __a, _IIter __b, _IIter __c, _IIter d) const
+      __count(_IIter __a, _IIter __b, _IIter __c, _IIter __d) const
       {
 	_DifferenceType __counter = 0;
 
-	while (__a != __b && __c != d)
+	while (__a != __b && __c != __d)
           {
             if (_M_comp(*__a, *__c))
               {
@@ -126,12 +126,12 @@ namespace __gnu_parallel
               }
           }
 
-	return __counter + (__b - __a) + (d - __c);
+	return __counter + (__b - __a) + (__d - __c);
       }
 
       _OutputIterator
-      __first_empty(_IIter __c, _IIter d, _OutputIterator __out) const
-      { return std::copy(__c, d, __out); }
+      __first_empty(_IIter __c, _IIter __d, _OutputIterator __out) const
+      { return std::copy(__c, __d, __out); }
 
       _OutputIterator
       __second_empty(_IIter __a, _IIter __b, _OutputIterator __out) const
@@ -153,10 +153,10 @@ namespace __gnu_parallel
       _Compare _M_comp;
 
       _OutputIterator
-      _M_invoke(_IIter __a, _IIter __b, _IIter __c, _IIter d,
+      _M_invoke(_IIter __a, _IIter __b, _IIter __c, _IIter __d,
 		_OutputIterator __r) const
       {
-	while (__a != __b && __c != d)
+	while (__a != __b && __c != __d)
           {
             if (_M_comp(*__a, *__c))
               {
@@ -177,11 +177,11 @@ namespace __gnu_parallel
 
       _DifferenceType
       __count(_IIter __a, _IIter __b,
-	      _IIter __c, _IIter d) const
+	      _IIter __c, _IIter __d) const
       {
 	_DifferenceType __counter = 0;
 
-	while (__a != __b && __c != d)
+	while (__a != __b && __c != __d)
           {
             if (_M_comp(*__a, *__c))
               {
diff --git a/libstdc++-v3/include/profile/impl/profiler_node.h b/libstdc++-v3/include/profile/impl/profiler_node.h
index d22a3e1..86f541f 100644
--- a/libstdc++-v3/include/profile/impl/profiler_node.h
+++ b/libstdc++-v3/include/profile/impl/profiler_node.h
@@ -148,7 +148,7 @@ namespace __gnu_profile
     __stack() const
     { return _M_stack; }
     
-    virtual void __write(FILE* f) const = 0;
+    virtual void __write(FILE* __f) const = 0;
 
   protected:
     __stack_t _M_stack;



More information about the Libstdc++ mailing list