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

Side by Side Diff: src/platform-win32.cc

Issue 1940: Replaced calls to functions that msvc consider deprecated. Used... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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 | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/prettyprinter.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Generate a pseudo-random number in the range 0-2^31-1. Usually 149 // Generate a pseudo-random number in the range 0-2^31-1. Usually
150 // defined in stdlib.h 150 // defined in stdlib.h
151 int random() { 151 int random() {
152 return rand(); 152 return rand();
153 } 153 }
154 154
155 155
156 // Case-insensitive string comparisons. Use stricmp() on Win32. Usually defined 156 // Case-insensitive string comparisons. Use stricmp() on Win32. Usually defined
157 // in strings.h. 157 // in strings.h.
158 int strcasecmp(const char* s1, const char* s2) { 158 int strcasecmp(const char* s1, const char* s2) {
159 return stricmp(s1, s2); 159 return _stricmp(s1, s2);
160 } 160 }
161 161
162 162
163 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually 163 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
164 // defined in strings.h. 164 // defined in strings.h.
165 int strncasecmp(const char* s1, const char* s2, int n) { 165 int strncasecmp(const char* s1, const char* s2, int n) {
166 return strnicmp(s1, s2, n); 166 return _strnicmp(s1, s2, n);
167 } 167 }
168 168
169 namespace v8 { namespace internal { 169 namespace v8 { namespace internal {
170 170
171 double ceiling(double x) { 171 double ceiling(double x) {
172 return ceil(x); 172 return ceil(x);
173 } 173 }
174 174
175 // ---------------------------------------------------------------------------- 175 // ----------------------------------------------------------------------------
176 // The Time class represents time on win32. A timestamp is represented as 176 // The Time class represents time on win32. A timestamp is represented as
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 tzinfo_.StandardDate.wDay = 5; 334 tzinfo_.StandardDate.wDay = 5;
335 tzinfo_.StandardDate.wHour = 3; 335 tzinfo_.StandardDate.wHour = 3;
336 tzinfo_.StandardBias = 0; 336 tzinfo_.StandardBias = 0;
337 tzinfo_.DaylightDate.wMonth = 3; 337 tzinfo_.DaylightDate.wMonth = 3;
338 tzinfo_.DaylightDate.wDay = 5; 338 tzinfo_.DaylightDate.wDay = 5;
339 tzinfo_.DaylightDate.wHour = 2; 339 tzinfo_.DaylightDate.wHour = 2;
340 tzinfo_.DaylightBias = -60; 340 tzinfo_.DaylightBias = -60;
341 } 341 }
342 342
343 // Make standard and DST timezone names. 343 // Make standard and DST timezone names.
344 _snprintf(std_tz_name_, kTzNameSize, "%S", tzinfo_.StandardName); 344 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize),
345 "%S",
346 tzinfo_.StandardName);
345 std_tz_name_[kTzNameSize - 1] = '\0'; 347 std_tz_name_[kTzNameSize - 1] = '\0';
346 _snprintf(dst_tz_name_, kTzNameSize, "%S", tzinfo_.DaylightName); 348 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize),
349 "%S",
350 tzinfo_.DaylightName);
347 dst_tz_name_[kTzNameSize - 1] = '\0'; 351 dst_tz_name_[kTzNameSize - 1] = '\0';
348 352
349 // If OS returned empty string or resource id (like "@tzres.dll,-211") 353 // If OS returned empty string or resource id (like "@tzres.dll,-211")
350 // simply guess the name from the UTC bias of the timezone. 354 // simply guess the name from the UTC bias of the timezone.
351 // To properly resolve the resource identifier requires a library load, 355 // To properly resolve the resource identifier requires a library load,
352 // which is not possible in a sandbox. 356 // which is not possible in a sandbox.
353 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') { 357 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') {
354 _snprintf(std_tz_name_, kTzNameSize - 1, "%s Standard Time", 358 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1),
355 GuessTimezoneNameFromBias(tzinfo_.Bias)); 359 "%s Standard Time",
360 GuessTimezoneNameFromBias(tzinfo_.Bias));
356 } 361 }
357 if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') { 362 if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') {
358 _snprintf(dst_tz_name_, kTzNameSize - 1, "%s Daylight Time", 363 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1),
359 GuessTimezoneNameFromBias(tzinfo_.Bias)); 364 "%s Daylight Time",
365 GuessTimezoneNameFromBias(tzinfo_.Bias));
360 } 366 }
361 367
362 // Timezone information initialized. 368 // Timezone information initialized.
363 tz_initialized_ = true; 369 tz_initialized_ = true;
364 } 370 }
365 371
366 372
367 // Return the difference in milliseconds between this and another timestamp. 373 // Return the difference in milliseconds between this and another timestamp.
368 int64_t Time::Diff(Time* other) { 374 int64_t Time::Diff(Time* other) {
369 return (t() - other->t()) / kTimeScaler; 375 return (t() - other->t()) / kTimeScaler;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 606 }
601 607
602 608
603 static void VPrintHelper(FILE* stream, const char* format, va_list args) { 609 static void VPrintHelper(FILE* stream, const char* format, va_list args) {
604 if (HasConsole()) { 610 if (HasConsole()) {
605 vfprintf(stream, format, args); 611 vfprintf(stream, format, args);
606 } else { 612 } else {
607 // It is important to use safe print here in order to avoid 613 // It is important to use safe print here in order to avoid
608 // overflowing the buffer. We might truncate the output, but this 614 // overflowing the buffer. We might truncate the output, but this
609 // does not crash. 615 // does not crash.
610 static const int kBufferSize = 4096; 616 EmbeddedVector<char, 4096> buffer;
611 char buffer[kBufferSize]; 617 OS::VSNPrintF(buffer, format, args);
612 OS::VSNPrintF(buffer, kBufferSize, format, args); 618 OutputDebugStringA(buffer.start());
613 OutputDebugStringA(buffer); 619 }
620 }
621
622
623 FILE* OS::FOpen(const char* path, const char* mode) {
624 FILE* result;
625 if (fopen_s(&result, path, mode) == 0) {
626 return result;
627 } else {
628 return NULL;
614 } 629 }
615 } 630 }
616 631
617 632
618 // Print (debug) message to console. 633 // Print (debug) message to console.
619 void OS::Print(const char* format, ...) { 634 void OS::Print(const char* format, ...) {
620 va_list args; 635 va_list args;
621 va_start(args, format); 636 va_start(args, format);
622 VPrint(format, args); 637 VPrint(format, args);
623 va_end(args); 638 va_end(args);
(...skipping 12 matching lines...) Expand all
636 VPrintError(format, args); 651 VPrintError(format, args);
637 va_end(args); 652 va_end(args);
638 } 653 }
639 654
640 655
641 void OS::VPrintError(const char* format, va_list args) { 656 void OS::VPrintError(const char* format, va_list args) {
642 VPrintHelper(stderr, format, args); 657 VPrintHelper(stderr, format, args);
643 } 658 }
644 659
645 660
646 int OS::SNPrintF(char* str, size_t size, const char* format, ...) { 661 int OS::SNPrintF(Vector<char> str, const char* format, ...) {
647 va_list args; 662 va_list args;
648 va_start(args, format); 663 va_start(args, format);
649 int result = VSNPrintF(str, size, format, args); 664 int result = VSNPrintF(str, format, args);
650 va_end(args); 665 va_end(args);
651 return result; 666 return result;
652 } 667 }
653 668
654 669
655 int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) { 670 int OS::VSNPrintF(Vector<char> str, const char* format, va_list args) {
656 // Print formated output to string. The _vsnprintf function has been 671 int n = _vsnprintf_s(str.start(), str.length(), str.length(), format, args);
657 // deprecated in MSVC. We need to define _CRT_NONSTDC_NO_DEPRECATE
658 // during compilation to use it anyway. Usually defined in stdio.h.
659 int n = _vsnprintf(str, size, format, args);
660 // Make sure to zero-terminate the string if the output was 672 // Make sure to zero-terminate the string if the output was
661 // truncated or if there was an error. 673 // truncated or if there was an error.
662 if (n < 0 || static_cast<size_t>(n) >= size) { 674 if (n < 0 || n >= str.length()) {
663 str[size - 1] = '\0'; 675 str[str.length() - 1] = '\0';
664 return -1; 676 return -1;
665 } else { 677 } else {
666 return n; 678 return n;
667 } 679 }
668 } 680 }
669 681
670 682
683 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
684 int result = strncpy_s(dest.start(), dest.length(), src, n);
685 USE(result); ASSERT(result == 0);
686 }
687
688
689 void OS::WcsCpy(Vector<wchar_t> dest, const wchar_t* src) {
690 int result = wcscpy_s(dest.start(), dest.length(), src);
691 USE(result); ASSERT(result == 0);
692 }
693
694
695 char *OS::StrDup(const char* str) {
696 return _strdup(str);
697 }
698
699
671 // We keep the lowest and highest addresses mapped as a quick way of 700 // We keep the lowest and highest addresses mapped as a quick way of
672 // determining that pointers are outside the heap (used mostly in assertions 701 // determining that pointers are outside the heap (used mostly in assertions
673 // and verification). The estimate is conservative, ie, not all addresses in 702 // and verification). The estimate is conservative, ie, not all addresses in
674 // 'allocated' space are actually allocated to our heap. The range is 703 // 'allocated' space are actually allocated to our heap. The range is
675 // [lowest, highest), inclusive on the low and and exclusive on the high end. 704 // [lowest, highest), inclusive on the low and and exclusive on the high end.
676 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); 705 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
677 static void* highest_ever_allocated = reinterpret_cast<void*>(0); 706 static void* highest_ever_allocated = reinterpret_cast<void*>(0);
678 707
679 708
680 static void UpdateAllocatedSpaceLimits(void* address, int size) { 709 static void UpdateAllocatedSpaceLimits(void* address, int size) {
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 Line.SizeOfStruct = sizeof(Line); 1154 Line.SizeOfStruct = sizeof(Line);
1126 DWORD line_displacement; 1155 DWORD line_displacement;
1127 ok = _SymGetLineFromAddr64( 1156 ok = _SymGetLineFromAddr64(
1128 process_handle, // hProcess 1157 process_handle, // hProcess
1129 stack_frame.AddrPC.Offset, // dwAddr 1158 stack_frame.AddrPC.Offset, // dwAddr
1130 &line_displacement, // pdwDisplacement 1159 &line_displacement, // pdwDisplacement
1131 &Line); // Line 1160 &Line); // Line
1132 // Format a text representation of the frame based on the information 1161 // Format a text representation of the frame based on the information
1133 // available. 1162 // available.
1134 if (ok) { 1163 if (ok) {
1135 SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s %s:%d:%d", 1164 SNPrintF(MutableCStrVector(frames[frames_count].text,
1165 kStackWalkMaxTextLen),
1166 "%s %s:%d:%d",
1136 symbol->Name, Line.FileName, Line.LineNumber, 1167 symbol->Name, Line.FileName, Line.LineNumber,
1137 line_displacement); 1168 line_displacement);
1138 } else { 1169 } else {
1139 SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s", 1170 SNPrintF(MutableCStrVector(frames[frames_count].text,
1171 kStackWalkMaxTextLen),
1172 "%s",
1140 symbol->Name); 1173 symbol->Name);
1141 } 1174 }
1142 // Make sure line termination is in place. 1175 // Make sure line termination is in place.
1143 frames[frames_count].text[kStackWalkMaxTextLen - 1] = '\0'; 1176 frames[frames_count].text[kStackWalkMaxTextLen - 1] = '\0';
1144 } else { 1177 } else {
1145 // No text representation of this frame 1178 // No text representation of this frame
1146 frames[frames_count].text[0] = '\0'; 1179 frames[frames_count].text[0] = '\0';
1147 1180
1148 // Continue if we are just missing a module (for non C/C++ frames a 1181 // Continue if we are just missing a module (for non C/C++ frames a
1149 // module will never be found). 1182 // module will never be found).
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 1563
1531 // Release the thread handles 1564 // Release the thread handles
1532 CloseHandle(data_->sampler_thread_); 1565 CloseHandle(data_->sampler_thread_);
1533 CloseHandle(data_->profiled_thread_); 1566 CloseHandle(data_->profiled_thread_);
1534 } 1567 }
1535 1568
1536 1569
1537 #endif // ENABLE_LOGGING_AND_PROFILING 1570 #endif // ENABLE_LOGGING_AND_PROFILING
1538 1571
1539 } } // namespace v8::internal 1572 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698