Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from code import Code | 5 from code import Code |
| 6 from model import PropertyType | 6 from model import PropertyType |
| 7 import cpp_util | 7 import cpp_util |
| 8 import schema_util | 8 import schema_util |
| 9 import util_cc_helper | 9 import util_cc_helper |
| 10 from cpp_namespace_environment import CppNamespaceEnvironment | 10 from cpp_namespace_environment import CppNamespaceEnvironment |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 else: | 881 else: |
| 882 (c.Append('if (!%%(cpp_type)s::Populate(%s))' % self._GenerateArgs( | 882 (c.Append('if (!%%(cpp_type)s::Populate(%s))' % self._GenerateArgs( |
| 883 ('*%(src_var)s', '&%(dst_var)s'))) | 883 ('*%(src_var)s', '&%(dst_var)s'))) |
| 884 .Append(' return %(failure_value)s;')) | 884 .Append(' return %(failure_value)s;')) |
| 885 elif underlying_type.property_type == PropertyType.ENUM: | 885 elif underlying_type.property_type == PropertyType.ENUM: |
| 886 c.Concat(self._GenerateStringToEnumConversion(underlying_type, | 886 c.Concat(self._GenerateStringToEnumConversion(underlying_type, |
| 887 src_var, | 887 src_var, |
| 888 dst_var, | 888 dst_var, |
| 889 failure_value)) | 889 failure_value)) |
| 890 elif underlying_type.property_type == PropertyType.BINARY: | 890 elif underlying_type.property_type == PropertyType.BINARY: |
| 891 (c.Append('const base::Value* binary_value = NULL;') | 891 (c.Sblock('if (!%(src_var)s->IsType(base::Value::Type::BINARY)) {') |
| 892 .Sblock('if (!%(src_var)s->IsType(base::Value::Type::BINARY)) {') | |
| 893 .Concat(self._GenerateError( | 892 .Concat(self._GenerateError( |
| 894 '"\'%%(key)s\': expected binary, got " + ' + | 893 '"\'%%(key)s\': expected binary, got " + ' + |
| 895 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) | 894 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) |
| 896 ) | 895 ) |
| 897 if not self._generate_error_messages: | 896 if not self._generate_error_messages: |
| 898 c.Append('return %(failure_value)s;') | 897 c.Append('return %(failure_value)s;') |
| 899 (c.Eblock('}') | 898 (c.Eblock('}') |
| 900 .Sblock('else {') | 899 .Sblock('else {') |
| 901 .Append(' binary_value =') | |
| 902 .Append(' static_cast<const base::Value*>(%(src_var)s);') | |
| 903 ) | 900 ) |
| 904 if is_ptr: | 901 if is_ptr: |
| 905 (c.Append('%(dst_var)s.reset(new std::vector<char>(') | 902 c.Append( |
| 906 .Append(' binary_value->GetBuffer(),') | 903 '%(dst_var)s.reset(new std::vector<char>(%(src_var)s->GetBlob()));') |
|
jdoerrie
2017/04/25 08:50:34
dst_var might be null, which caused the SIGSEGV on
| |
| 907 .Append(' binary_value->GetBuffer() + binary_value->GetSize()));') | |
| 908 ) | |
| 909 else: | 904 else: |
| 910 (c.Append('%(dst_var)s.assign(') | 905 c.Append('%(dst_var)s = %(src_var)s->GetBlob();') |
| 911 .Append(' binary_value->GetBuffer(),') | |
| 912 .Append(' binary_value->GetBuffer() + binary_value->GetSize());') | |
| 913 ) | |
| 914 c.Eblock('}') | 906 c.Eblock('}') |
| 915 else: | 907 else: |
| 916 raise NotImplementedError(type_) | 908 raise NotImplementedError(type_) |
| 917 if c.IsEmpty(): | 909 if c.IsEmpty(): |
| 918 return c | 910 return c |
| 919 return Code().Sblock('{').Concat(c.Substitute({ | 911 return Code().Sblock('{').Concat(c.Substitute({ |
| 920 'cpp_type': self._type_helper.GetCppType(type_), | 912 'cpp_type': self._type_helper.GetCppType(type_), |
| 921 'src_var': src_var, | 913 'src_var': src_var, |
| 922 'dst_var': dst_var, | 914 'dst_var': dst_var, |
| 923 'failure_value': failure_value, | 915 'failure_value': failure_value, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 if self._generate_error_messages: | 1148 if self._generate_error_messages: |
| 1157 params = list(params) + ['base::string16* error'] | 1149 params = list(params) + ['base::string16* error'] |
| 1158 return ', '.join(str(p) for p in params) | 1150 return ', '.join(str(p) for p in params) |
| 1159 | 1151 |
| 1160 def _GenerateArgs(self, args): | 1152 def _GenerateArgs(self, args): |
| 1161 """Builds the argument list for a function, given an array of arguments. | 1153 """Builds the argument list for a function, given an array of arguments. |
| 1162 """ | 1154 """ |
| 1163 if self._generate_error_messages: | 1155 if self._generate_error_messages: |
| 1164 args = list(args) + ['error'] | 1156 args = list(args) + ['error'] |
| 1165 return ', '.join(str(a) for a in args) | 1157 return ', '.join(str(a) for a in args) |
| OLD | NEW |