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

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

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Format string fixes Created 5 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 unified diff | Download patch
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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 } 2508 }
2509 // Not a closure of a top level method or static function, throw an 2509 // Not a closure of a top level method or static function, throw an
2510 // exception as we do not allow these objects to be serialized. 2510 // exception as we do not allow these objects to be serialized.
2511 HANDLESCOPE(thread()); 2511 HANDLESCOPE(thread());
2512 2512
2513 const Class& clazz = Class::Handle(isolate(), cls); 2513 const Class& clazz = Class::Handle(isolate(), cls);
2514 const Function& errorFunc = Function::Handle(isolate(), func); 2514 const Function& errorFunc = Function::Handle(isolate(), func);
2515 ASSERT(!errorFunc.IsNull()); 2515 ASSERT(!errorFunc.IsNull());
2516 2516
2517 // All other closures are errors. 2517 // All other closures are errors.
2518 const char* format = "Illegal argument in isolate message"
2519 " : (object is a closure - %s %s)";
2520 UnmarkAll(); // Unmark objects now as we are about to print stuff. 2518 UnmarkAll(); // Unmark objects now as we are about to print stuff.
2521 intptr_t len = OS::SNPrint(NULL, 0, format, 2519 char* chars = NULL;
2522 clazz.ToCString(), errorFunc.ToCString()) + 1; 2520 SNPRINT(chars, thread()->zone()->Alloc<char>,
2523 char* chars = thread()->zone()->Alloc<char>(len); 2521 "Illegal argument in isolate message : (object is a closure - %s %s)",
2524 OS::SNPrint(chars, len, format, clazz.ToCString(), errorFunc.ToCString()); 2522 clazz.ToCString(), errorFunc.ToCString());
2525 SetWriteException(Exceptions::kArgument, chars); 2523 SetWriteException(Exceptions::kArgument, chars);
2526 } 2524 }
2527 return Function::null(); 2525 return Function::null();
2528 } 2526 }
2529 2527
2530 2528
2531 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) { 2529 RawClass* SnapshotWriter::GetFunctionOwner(RawFunction* func) {
2532 RawObject* owner = func->ptr()->owner_; 2530 RawObject* owner = func->ptr()->owner_;
2533 uword tags = GetObjectTags(owner); 2531 uword tags = GetObjectTags(owner);
2534 intptr_t class_id = RawObject::ClassIdTag::decode(tags); 2532 intptr_t class_id = RawObject::ClassIdTag::decode(tags);
2535 if (class_id == kClassCid) { 2533 if (class_id == kClassCid) {
2536 return reinterpret_cast<RawClass*>(owner); 2534 return reinterpret_cast<RawClass*>(owner);
2537 } 2535 }
2538 ASSERT(class_id == kPatchClassCid); 2536 ASSERT(class_id == kPatchClassCid);
2539 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_; 2537 return reinterpret_cast<RawPatchClass*>(owner)->ptr()->patched_class_;
2540 } 2538 }
2541 2539
2542 2540
2543 void SnapshotWriter::CheckForNativeFields(RawClass* cls) { 2541 void SnapshotWriter::CheckForNativeFields(RawClass* cls) {
2544 if (cls->ptr()->num_native_fields_ != 0) { 2542 if (cls->ptr()->num_native_fields_ != 0) {
2545 // We do not allow objects with native fields in an isolate message. 2543 // We do not allow objects with native fields in an isolate message.
2546 HANDLESCOPE(thread()); 2544 HANDLESCOPE(thread());
2547 const char* format = "Illegal argument in isolate message"
2548 " : (object extends NativeWrapper - %s)";
2549 UnmarkAll(); // Unmark objects now as we are about to print stuff. 2545 UnmarkAll(); // Unmark objects now as we are about to print stuff.
2550 const Class& clazz = Class::Handle(isolate(), cls); 2546 const Class& clazz = Class::Handle(isolate(), cls);
2551 intptr_t len = OS::SNPrint(NULL, 0, format, clazz.ToCString()) + 1; 2547 char* chars = NULL;
2552 char* chars = thread()->zone()->Alloc<char>(len); 2548 SNPRINT(chars, thread()->zone()->Alloc<char>,
2553 OS::SNPrint(chars, len, format, clazz.ToCString()); 2549 "Illegal argument in isolate message"
2550 " : (object extends NativeWrapper - %s)",
2551 clazz.ToCString());
2554 SetWriteException(Exceptions::kArgument, chars); 2552 SetWriteException(Exceptions::kArgument, chars);
2555 } 2553 }
2556 } 2554 }
2557 2555
2558 2556
2559 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type, 2557 void SnapshotWriter::SetWriteException(Exceptions::ExceptionType type,
2560 const char* msg) { 2558 const char* msg) {
2561 set_exception_type(type); 2559 set_exception_type(type);
2562 set_exception_msg(msg); 2560 set_exception_msg(msg);
2563 // The more specific error is set up in SnapshotWriter::ThrowException(). 2561 // The more specific error is set up in SnapshotWriter::ThrowException().
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 NoSafepointScope no_safepoint; 2786 NoSafepointScope no_safepoint;
2789 WriteObject(obj.raw()); 2787 WriteObject(obj.raw());
2790 UnmarkAll(); 2788 UnmarkAll();
2791 } else { 2789 } else {
2792 ThrowException(exception_type(), exception_msg()); 2790 ThrowException(exception_type(), exception_msg());
2793 } 2791 }
2794 } 2792 }
2795 2793
2796 2794
2797 } // namespace dart 2795 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698