config/make-atom-strings.pl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 #! perl
     2 # This Source Code Form is subject to the terms of the Mozilla Public
     3 # License, v. 2.0. If a copy of the MPL was not distributed with this
     4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 # Converts a list of atoms in the form:
     8 # // OUTPUT_CLASS=<classname>
     9 # // MACRO_NAME=<macro>
    10 # <macroname>(atomName, "String")
    11 # <macroname>(atomName2, "String2")
    12 #
    13 # into a file suitable for gperf using static atoms
    14 #
    15 # usage:
    16 # make-atom-strings < file.h > file.gperf
    17 #
    18 # the lines in the C++ comments define two variables:
    19 # OUTPUT_CLASS is the class who has all the atoms as members
    20 # MACRO_NAME is the macro to look for in the rest of the file
    21 #
    22 # for example
    23 # // OUTPUT_CLASS=nsHTMLAtoms
    24 # // MACRO_NAME=HTML_ATOM
    25 # HTML_ATOM(a, "a")
    26 # HTML_ATOM(body, "body")
    27 #
    28 # etc...
    29 #
    30 # this will generate a file that looks like:
    31 # struct nsStaticAtom ( const char* mValue; nsIAtom** aAtom; }
    32 # %%
    33 # "a", &nsHTMLAtoms::a
    34 # "body", &nsHTMLAtoms::body
    35 #
    36 # etc...
    37 #
    38 # the output can be plugged into gperf to generate a perfect hash
    40 print "struct nsStaticAtom {const char* mValue; nsIAtom** aAtom; };\n";
    41 print "%%\n";
    43 my $classname, $macroname;
    45 while (<>) {
    46   chop;
    47   if (/OUTPUT_CLASS=(\S+)/) {
    48     $classname=$1;
    49   } elsif (/MACRO_NAME=(\S+)/) {
    50     $macroname=$1;
    51   }
    52   elsif ($classname && $macroname &&
    53          /$macroname\((\S+),\s*\"(.*?)\"\s*\)/) {
    54     my ($str, $atom) = ($2, $1);
    55     print "\"$str\", (nsIAtom**)&${classname}::$atom\n";
    56   }
    57 }

mercurial