Merge pull request #4811 from htuch/invalid-name-json

json: include field name in InvalidName status messages.
diff --git a/benchmarks/python/py_benchmark.py b/benchmarks/python/py_benchmark.py
index 6942d20..e86b61e 100755
--- a/benchmarks/python/py_benchmark.py
+++ b/benchmarks/python/py_benchmark.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 import sys
 import os
 import timeit
@@ -138,15 +139,15 @@
     results.append(run_one_test(file))
   
   if args.json != "no":
-    print json.dumps(results)
+    print(json.dumps(results))
   else:
     for result in results:
-      print "Message %s of dataset file %s" % \
-          (result["message_name"], result["filename"])
-      print "Average time for parse_from_benchmark: %.2f ns" % \
+      print("Message %s of dataset file %s" % \
+          (result["message_name"], result["filename"]))
+      print("Average time for parse_from_benchmark: %.2f ns" % \
           (result["benchmarks"][ \
-                      args.behavior_prefix + "_parse_from_benchmark"])
-      print "Average time for serialize_to_benchmark: %.2f ns" % \
+                      args.behavior_prefix + "_parse_from_benchmark"]))
+      print("Average time for serialize_to_benchmark: %.2f ns" % \
           (result["benchmarks"][ \
-                      args.behavior_prefix + "_serialize_to_benchmark"])
-      print ""
+                      args.behavior_prefix + "_serialize_to_benchmark"]))
+      print("")
diff --git a/benchmarks/util/big_query_utils.py b/benchmarks/util/big_query_utils.py
index 14105aa..aea55bb 100755
--- a/benchmarks/util/big_query_utils.py
+++ b/benchmarks/util/big_query_utils.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python2.7
 
+from __future__ import print_function
 import argparse
 import json
 import uuid
@@ -37,11 +38,11 @@
         dataset_req.execute(num_retries=NUM_RETRIES)
     except HttpError as http_error:
         if http_error.resp.status == 409:
-            print 'Warning: The dataset %s already exists' % dataset_id
+            print('Warning: The dataset %s already exists' % dataset_id)
         else:
             # Note: For more debugging info, print "http_error.content"
-            print 'Error in creating dataset: %s. Err: %s' % (dataset_id,
-                                                              http_error)
+            print('Error in creating dataset: %s. Err: %s' % (dataset_id,
+                                                              http_error))
             is_success = False
     return is_success
 
@@ -109,13 +110,13 @@
         table_req = big_query.tables().insert(
             projectId=project_id, datasetId=dataset_id, body=body)
         res = table_req.execute(num_retries=NUM_RETRIES)
-        print 'Successfully created %s "%s"' % (res['kind'], res['id'])
+        print('Successfully created %s "%s"' % (res['kind'], res['id']))
     except HttpError as http_error:
         if http_error.resp.status == 409:
-            print 'Warning: Table %s already exists' % table_id
+            print('Warning: Table %s already exists' % table_id)
         else:
-            print 'Error in creating table: %s. Err: %s' % (table_id,
-                                                            http_error)
+            print('Error in creating table: %s. Err: %s' % (table_id,
+                                                            http_error))
             is_success = False
     return is_success
 
@@ -141,9 +142,9 @@
             tableId=table_id,
             body=body)
         res = table_req.execute(num_retries=NUM_RETRIES)
-        print 'Successfully patched %s "%s"' % (res['kind'], res['id'])
+        print('Successfully patched %s "%s"' % (res['kind'], res['id']))
     except HttpError as http_error:
-        print 'Error in creating table: %s. Err: %s' % (table_id, http_error)
+        print('Error in creating table: %s. Err: %s' % (table_id, http_error))
         is_success = False
     return is_success
 
@@ -159,10 +160,10 @@
             body=body)
         res = insert_req.execute(num_retries=NUM_RETRIES)
         if res.get('insertErrors', None):
-            print 'Error inserting rows! Response: %s' % res
+            print('Error inserting rows! Response: %s' % res)
             is_success = False
     except HttpError as http_error:
-        print 'Error inserting rows to the table %s' % table_id
+        print('Error inserting rows to the table %s' % table_id)
         is_success = False
 
     return is_success
@@ -176,8 +177,8 @@
             projectId=project_id,
             body=query_data).execute(num_retries=NUM_RETRIES)
     except HttpError as http_error:
-        print 'Query execute job failed with error: %s' % http_error
-        print http_error.content
+        print('Query execute job failed with error: %s' % http_error)
+        print(http_error.content)
     return query_job
 
 
diff --git a/benchmarks/util/run_and_upload.py b/benchmarks/util/run_and_upload.py
index ae22a66..43c9fa2 100755
--- a/benchmarks/util/run_and_upload.py
+++ b/benchmarks/util/run_and_upload.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+from __future__ import absolute_import
 import argparse
 import os
 import re
@@ -5,7 +7,7 @@
 import uuid
 import calendar
 import time
-import big_query_utils
+from . import big_query_utils
 import datetime
 import json
 # This import depends on the automake rule protoc_middleman, please make sure
@@ -255,7 +257,7 @@
     if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET,
                                        _TABLE + "$" + _NOW,
                                        [row]):
-      print 'Error when uploading result', new_result
+      print('Error when uploading result', new_result)
 
 
 if __name__ == "__main__":
@@ -280,11 +282,11 @@
   parse_go_result(args.go_input_file)
 
   metadata = get_metadata()
-  print "uploading cpp results..."
+  print("uploading cpp results...")
   upload_result(cpp_result, metadata)
-  print "uploading java results..."
+  print("uploading java results...")
   upload_result(java_result, metadata)
-  print "uploading python results..."
+  print("uploading python results...")
   upload_result(python_result, metadata)
-  print "uploading go results..."
+  print("uploading go results...")
   upload_result(go_result, metadata)
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index d8282e4..7109ed5 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -3477,7 +3477,8 @@
     GenerateExtension(options, printer, *it);
   }
 
-  if (options.import_style == GeneratorOptions::kImportCommonJs) {
+  // if provided is empty, do not export anything
+  if (options.import_style == GeneratorOptions::kImportCommonJs && !provided.empty()) {
     printer->Print("goog.object.extend(exports, $package$);\n",
                    "package", GetFilePath(options, file));
   }
diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h
index c3a64dd..ff4dea7 100644
--- a/src/google/protobuf/stubs/platform_macros.h
+++ b/src/google/protobuf/stubs/platform_macros.h
@@ -99,6 +99,7 @@
 
 #if defined(__APPLE__)
 #define GOOGLE_PROTOBUF_OS_APPLE
+#include <Availability.h>
 #include <TargetConditionals.h>
 #if TARGET_OS_IPHONE
 #define GOOGLE_PROTOBUF_OS_IPHONE
@@ -125,4 +126,9 @@
 #define GOOGLE_PROTOBUF_NO_THREADLOCAL
 #endif
 
+#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+// __thread keyword requires at least 10.7
+#define GOOGLE_PROTOBUF_NO_THREADLOCAL
+#endif
+
 #endif  // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_