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

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 10815024: Revert 147594 - NaCl: Remove two uses of '#include "nacl/nacl_log.h"' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
Index: tools/json_schema_compiler/cc_generator.py
===================================================================
--- tools/json_schema_compiler/cc_generator.py (revision 147600)
+++ tools/json_schema_compiler/cc_generator.py (working copy)
@@ -355,7 +355,12 @@
elif prop.type_ == PropertyType.ENUM:
return 'CreateEnumValue(%s).release()' % var
elif prop.type_ == PropertyType.BINARY:
- return '%s->DeepCopy()' % var
+ if prop.optional:
+ vardot = var + '->'
+ else:
+ vardot = var + '.'
+ return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' %
+ (vardot, vardot))
elif self._IsArrayOrArrayRef(prop):
return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
self._cpp_type_generator.GetReferencedProperty(prop), var,
@@ -542,15 +547,20 @@
c.Append('%(dst)s->%(name)s = enum_temp;')
c.Eblock('}')
elif prop.type_ == PropertyType.BINARY:
- # This is the same if the property is optional or not. We need a pointer
- # to the base::BinaryValue to be able to populate it, so a scoped_ptr is
- # used whether it is optional or required.
(c.Append('if (!%(value_var)s->IsType(%(value_type)s))')
.Append(' return %(failure_value)s;')
- .Append('%(dst)s->%(name)s.reset(')
- .Append(' static_cast<base::BinaryValue*>(%(value_var)s)'
- '->DeepCopy());')
- )
+ .Append('base::BinaryValue* binary_value =')
+ .Append(' static_cast<base::BinaryValue*>(%(value_var)s);')
+ )
+ if prop.optional:
+ (c.Append('%(dst)s->%(name)s.reset(')
+ .Append(' new std::string(binary_value->GetBuffer(),')
+ .Append(' binary_value->GetSize()));')
+ )
+ else:
+ (c.Append('%(dst)s->%(name)s.assign(binary_value->GetBuffer(),')
+ .Append(' binary_value->GetSize());')
+ )
else:
raise NotImplementedError(prop.type_)
c.Eblock('}')
« no previous file with comments | « ppapi/native_client/tests/ppapi_example_audio/audio.cc ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698