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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 12419009: Fix build break in dart2js. The snapshot length was not accounting for the magic number. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/dartutils.h ('k') | no next file » | 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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "bin/extensions.h" 7 #include "bin/extensions.h"
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/file.h" 9 #include "bin/file.h"
10 #include "bin/io_buffer.h" 10 #include "bin/io_buffer.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 result = DartUtils::LoadSource(NULL, 335 result = DartUtils::LoadSource(NULL,
336 library, 336 library,
337 url, 337 url,
338 tag, 338 tag,
339 url_string); 339 url_string);
340 return result; 340 return result;
341 } 341 }
342 342
343 343
344 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, 344 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer,
345 intptr_t* buffer_len,
345 bool* is_snapshot) { 346 bool* is_snapshot) {
346 intptr_t len = sizeof(magic_number); 347 intptr_t len = sizeof(magic_number);
347 for (intptr_t i = 0; i < len; i++) { 348 for (intptr_t i = 0; i < len; i++) {
348 if (text_buffer[i] != magic_number[i]) { 349 if (text_buffer[i] != magic_number[i]) {
349 *is_snapshot = false; 350 *is_snapshot = false;
350 return text_buffer; 351 return text_buffer;
351 } 352 }
352 } 353 }
353 *is_snapshot = true; 354 *is_snapshot = true;
355 ASSERT(*buffer_len > len);
356 *buffer_len -= len;
354 return text_buffer + len; 357 return text_buffer + len;
355 } 358 }
356 359
357 360
358 void DartUtils::WriteMagicNumber(File* file) { 361 void DartUtils::WriteMagicNumber(File* file) {
359 // Write a magic number and version information into the snapshot file. 362 // Write a magic number and version information into the snapshot file.
360 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); 363 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number));
361 ASSERT(bytes_written); 364 ASSERT(bytes_written);
362 } 365 }
363 366
(...skipping 12 matching lines...) Expand all
376 } 379 }
377 const char* script_path_cstr; 380 const char* script_path_cstr;
378 Dart_StringToCString(script_path, &script_path_cstr); 381 Dart_StringToCString(script_path, &script_path_cstr);
379 const char* error_msg = NULL; 382 const char* error_msg = NULL;
380 intptr_t len; 383 intptr_t len;
381 const uint8_t* text_buffer = ReadFile(script_path_cstr, &len, &error_msg); 384 const uint8_t* text_buffer = ReadFile(script_path_cstr, &len, &error_msg);
382 if (text_buffer == NULL) { 385 if (text_buffer == NULL) {
383 return Dart_Error(error_msg); 386 return Dart_Error(error_msg);
384 } 387 }
385 bool is_snapshot = false; 388 bool is_snapshot = false;
386 text_buffer = SniffForMagicNumber(text_buffer, &is_snapshot); 389 text_buffer = SniffForMagicNumber(text_buffer, &len, &is_snapshot);
387 if (is_snapshot) { 390 if (is_snapshot) {
388 return Dart_LoadScriptFromSnapshot(text_buffer, len); 391 return Dart_LoadScriptFromSnapshot(text_buffer, len);
389 } else { 392 } else {
390 Dart_Handle source = Dart_NewStringFromUTF8(text_buffer, len); 393 Dart_Handle source = Dart_NewStringFromUTF8(text_buffer, len);
391 return Dart_LoadScript(resolved_script_uri, source, 0, 0); 394 return Dart_LoadScript(resolved_script_uri, source, 0, 0);
392 } 395 }
393 } 396 }
394 397
395 398
396 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping, 399 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping,
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 737
735 CObject* CObject::NewOSError(OSError* os_error) { 738 CObject* CObject::NewOSError(OSError* os_error) {
736 CObject* error_message = 739 CObject* error_message =
737 new CObjectString(CObject::NewString(os_error->message())); 740 new CObjectString(CObject::NewString(os_error->message()));
738 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 741 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
739 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 742 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
740 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 743 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
741 result->SetAt(2, error_message); 744 result->SetAt(2, error_message);
742 return result; 745 return result;
743 } 746 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698