Bug 853111 - Kill -Wnarrowing warnings for zipped selfhosted sources. (r=till)
authorShu-yu Guo <shu@rfrn.org>
Thu, 21 Mar 2013 12:07:33 -0700
changeset 125836 dee55e5465e51cd14643492dbb3867bfc55c85ac
parent 125835 4504520f7f244f5eba3d17a63c995ed27a263b67
child 125837 c12a7b9d6ab65cc87ac4a117e46b5c46c08cdd5f
push id25115
push usershu@rfrn.org
push dateThu, 21 Mar 2013 20:18:14 +0000
treeherdermozilla-inbound@dee55e5465e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs853111
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 853111 - Kill -Wnarrowing warnings for zipped selfhosted sources. (r=till)
js/src/builtin/embedjs.py
--- a/js/src/builtin/embedjs.py
+++ b/js/src/builtin/embedjs.py
@@ -57,39 +57,31 @@ def ToCArray(lines):
 
 HEADER_TEMPLATE = """\
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 namespace js {
 namespace selfhosted {
-  static const char data[] = { %(sources_data)s };
+	static const %(sources_type)s data[] = { %(sources_data)s };
 
-%(sources_declaration)s
+	static const %(sources_type)s *%(sources_name)s = reinterpret_cast<const %(sources_type)s *>(data);
 
   uint32_t GetCompressedSize() {
     return %(compressed_total_length)i;
   }
 
   uint32_t GetRawScriptsSize() {
     return %(raw_total_length)i;
   }
 } // selfhosted
 } // js
 """
 
-RAW_SOURCES_DECLARATION = """\
-  static const char *rawSources = reinterpret_cast<const char *>(data);
-"""
-
-COMPRESSED_SOURCES_DECLARATION = """\
-  static const unsigned char *compressedSources = reinterpret_cast<const unsigned char *>(data);
-"""
-
 def embed(cpp, msgs, sources, c_out, js_out, env):
   # Clang seems to complain and not output anything if the extension of the
   # input is not something it recognizes, so just fake a .h here.
   tmp = 'selfhosted.js.h'
   with open(tmp, 'wb') as output:
     output.write('\n'.join([msgs] + ['#include "%(s)s"' % { 's': source } for source in sources]))
   cmdline = cpp + ['-D%(k)s=%(v)s' % { 'k': k, 'v': env[k] } for k in env] + [tmp]
   p = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
@@ -101,26 +93,28 @@ def embed(cpp, msgs, sources, c_out, js_
   with open(js_out, 'w') as output:
     output.write(processed)
   with open(c_out, 'w') as output:
     if 'USE_ZLIB' in env:
       import zlib
       compressed = zlib.compress(processed)
       data = ToCArray(compressed)
       output.write(HEADER_TEMPLATE % {
+          'sources_type': 'unsigned char',
           'sources_data': data,
-          'sources_declaration': COMPRESSED_SOURCES_DECLARATION,
+          'sources_name': 'compressedSources',
           'compressed_total_length': len(compressed),
           'raw_total_length': len(processed)
       })
     else:
       data = ToCAsciiArray(processed)
       output.write(HEADER_TEMPLATE % {
+          'sources_type': 'char',
           'sources_data': data,
-          'sources_declaration': RAW_SOURCES_DECLARATION,
+          'sources_name': 'rawSources',
           'compressed_total_length': 0,
           'raw_total_length': len(processed)
       })
 
 def process_msgs(cpp, msgs):
   # Clang seems to complain and not output anything if the extension of the
   # input is not something it recognizes, so just fake a .h here.
   tmp = 'selfhosted.msg.h'