Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: runtime/PRESUBMIT.py

Issue 23578046: Replace the memcpy macro with a lint check. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/eventhandler_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/PRESUBMIT.py
===================================================================
--- runtime/PRESUBMIT.py (revision 27636)
+++ runtime/PRESUBMIT.py (working copy)
@@ -4,6 +4,7 @@
import os
import cpplint
+import re
class PathHackException(Exception):
@@ -54,6 +55,7 @@
def RunLint(input_api, output_api):
result = []
cpplint._cpplint_state.ResetErrorCounts()
+ memcpy_match_count = 0
# Find all .cc and .h files in the change list.
for svn_file in input_api.AffectedTextFiles():
filename = svn_file.AbsoluteLocalPath()
@@ -71,8 +73,23 @@
cpplint.ProcessFile(filename, 1)
if cleanup is not None:
cleanup()
+ # memcpy does not handle overlapping memory regions. Even though this
+ # is well documented it seems to be used in error quite often. To avoid
+ # problems we disallow the direct use of memcpy. The exceptions are in
+ # third-party code and in platform/globals.h which uses it to implement
+ # bit_cast and bit_copy.
+ if not filename.endswith(os.path.join('platform', 'globals.h')) and \
+ filename.find('third_party') == -1:
+ fh = open(filename, 'r')
+ content = fh.read()
+ match = re.search('\\bmemcpy\\b', content)
+ if match:
+ line_number = content[0:match.start()].count('\n') + 1
+ print "%s:%d: use of memcpy is forbidden" % (filename, line_number)
+ memcpy_match_count += 1
+
# Report a presubmit error if any of the files had an error.
- if cpplint._cpplint_state.error_count > 0:
+ if cpplint._cpplint_state.error_count > 0 or memcpy_match_count > 0:
result = [output_api.PresubmitError('Failed cpplint check.')]
return result
« no previous file with comments | « no previous file | runtime/bin/eventhandler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698