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

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 11365243: Revert OneByteString back to ISO Latin-1 instead of ASCII (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
8 #include "vm/symbols.h" 8 #include "vm/symbols.h"
9 #include "vm/unicode.h" 9 #include "vm/unicode.h"
10 10
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 case kDoubleCid: { 340 case kDoubleCid: {
341 // Read the double value for the object. 341 // Read the double value for the object.
342 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); 342 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>());
343 AddBackRef(object_id, object, kIsDeserialized); 343 AddBackRef(object_id, object, kIsDeserialized);
344 return object; 344 return object;
345 } 345 }
346 case kOneByteStringCid: { 346 case kOneByteStringCid: {
347 intptr_t len = ReadSmiValue(); 347 intptr_t len = ReadSmiValue();
348 intptr_t hash = ReadSmiValue(); 348 intptr_t hash = ReadSmiValue();
349 USE(hash); 349 USE(hash);
350 Dart_CObject* object = AllocateDartCObjectString(len); 350 uint8_t *latin1 =
351 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t)));
352 intptr_t utf8_len = 0;
353 for (intptr_t i = 0; i < len; i++) {
354 latin1[i] = Read<uint8_t>();
355 utf8_len += Utf8::Length(latin1[i]);
356 }
357 Dart_CObject* object = AllocateDartCObjectString(utf8_len);
351 AddBackRef(object_id, object, kIsDeserialized); 358 AddBackRef(object_id, object, kIsDeserialized);
352 char* p = object->value.as_string; 359 char* p = object->value.as_string;
353 for (intptr_t i = 0; i < len; i++) { 360 for (intptr_t i = 0; i < len; i++) {
354 p[i] = Read<uint8_t>(); 361 p += Utf8::Encode(latin1[i], p);
355 } 362 }
356 p[len] = '\0'; 363 *p = '\0';
364 ASSERT(p == (object->value.as_string + utf8_len));
365 ::free(latin1);
357 return object; 366 return object;
358 } 367 }
359 case kTwoByteStringCid: { 368 case kTwoByteStringCid: {
360 intptr_t len = ReadSmiValue(); 369 intptr_t len = ReadSmiValue();
361 intptr_t hash = ReadSmiValue(); 370 intptr_t hash = ReadSmiValue();
362 USE(hash); 371 USE(hash);
363 uint16_t *utf16 = 372 uint16_t *utf16 =
364 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t))); 373 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t)));
365 intptr_t utf8_len = 0; 374 intptr_t utf8_len = 0;
366 for (intptr_t i = 0; i < len; i++) { 375 for (intptr_t i = 0; i < len; i++) {
367 utf16[i] = Read<uint16_t>(); 376 utf16[i] = Read<uint16_t>();
368 // TODO(sgjesse): Check for surrogate pairs. 377 // TODO(sgjesse): Check for surrogate pairs.
369 utf8_len += Utf8::Length(utf16[i]); 378 utf8_len += Utf8::Length(utf16[i]);
370 } 379 }
371 Dart_CObject* object = AllocateDartCObjectString(utf8_len); 380 Dart_CObject* object = AllocateDartCObjectString(utf8_len);
372 AddBackRef(object_id, object, kIsDeserialized); 381 AddBackRef(object_id, object, kIsDeserialized);
373 char* p = object->value.as_string; 382 char* p = object->value.as_string;
374 for (intptr_t i = 0; i < len; i++) { 383 for (intptr_t i = 0; i < len; i++) {
375 // TODO(sgjesse): Check for surrogate pairs. 384 // TODO(sgjesse): Check for surrogate pairs.
376 p += Utf8::Encode(utf16[i], p); 385 p += Utf8::Encode(utf16[i], p);
377 } 386 }
378 *p = '\0'; 387 *p = '\0';
379 ASSERT(p == object->value.as_string + utf8_len); 388 ASSERT(p == (object->value.as_string + utf8_len));
380 ::free(utf16); 389 ::free(utf16);
381 return object; 390 return object;
382 } 391 }
383 case kUint8ArrayCid: { 392 case kUint8ArrayCid: {
384 intptr_t len = ReadSmiValue(); 393 intptr_t len = ReadSmiValue();
385 Dart_CObject* object = AllocateDartCObjectUint8Array(len); 394 Dart_CObject* object = AllocateDartCObjectUint8Array(len);
386 AddBackRef(object_id, object, kIsDeserialized); 395 AddBackRef(object_id, object, kIsDeserialized);
387 if (len > 0) { 396 if (len > 0) {
388 uint8_t* p = object->value.as_byte_array.values; 397 uint8_t* p = object->value.as_byte_array.values;
389 for (intptr_t i = 0; i < len; i++) { 398 for (intptr_t i = 0; i < len; i++) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (!Utf8::IsValid(utf8_str, utf8_len)) { 774 if (!Utf8::IsValid(utf8_str, utf8_len)) {
766 return false; 775 return false;
767 } 776 }
768 777
769 Utf8::Type type; 778 Utf8::Type type;
770 intptr_t len = Utf8::CodePointCount(utf8_str, utf8_len, &type); 779 intptr_t len = Utf8::CodePointCount(utf8_str, utf8_len, &type);
771 780
772 // Write out the serialization header value for this object. 781 // Write out the serialization header value for this object.
773 WriteInlinedHeader(object); 782 WriteInlinedHeader(object);
774 // Write out the class and tags information. 783 // Write out the class and tags information.
775 WriteIndexedObject(type == Utf8::kAscii ? kOneByteStringCid 784 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid
776 : kTwoByteStringCid); 785 : kTwoByteStringCid);
777 WriteIntptrValue(0); 786 WriteIntptrValue(0);
778 // Write string length, hash and content 787 // Write string length, hash and content
779 WriteSmi(len); 788 WriteSmi(len);
780 WriteSmi(0); // TODO(sgjesse): Hash - not written. 789 WriteSmi(0); // TODO(sgjesse): Hash - not written.
781 if (type == Utf8::kAscii) { 790 if (type == Utf8::kLatin1) {
791 uint8_t* latin1_str =
792 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t)));
793 Utf8::DecodeToLatin1(utf8_str, utf8_len, latin1_str, len);
782 for (intptr_t i = 0; i < len; i++) { 794 for (intptr_t i = 0; i < len; i++) {
783 Write<uint8_t>(utf8_str[i]); 795 Write<uint8_t>(latin1_str[i]);
784 } 796 }
797 ::free(latin1_str);
785 } else { 798 } else {
786 // TODO(sgjesse): Make sure surrogate pairs are handled. 799 // TODO(sgjesse): Make sure surrogate pairs are handled.
787 uint16_t* utf16_str = 800 uint16_t* utf16_str =
788 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t))); 801 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t)));
789 Utf8::DecodeToUTF16(utf8_str, utf8_len, utf16_str, len); 802 Utf8::DecodeToUTF16(utf8_str, utf8_len, utf16_str, len);
790 for (intptr_t i = 0; i < len; i++) { 803 for (intptr_t i = 0; i < len; i++) {
791 Write<uint16_t>(utf16_str[i]); 804 Write<uint16_t>(utf16_str[i]);
792 } 805 }
793 ::free(utf16_str); 806 ::free(utf16_str);
794 } 807 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 if (!success) { 865 if (!success) {
853 UnmarkAllCObjects(object); 866 UnmarkAllCObjects(object);
854 return false; 867 return false;
855 } 868 }
856 } 869 }
857 UnmarkAllCObjects(object); 870 UnmarkAllCObjects(object);
858 return true; 871 return true;
859 } 872 }
860 873
861 } // namespace dart 874 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698