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.

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

mercurial