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

Side by Side Diff: src/utils.h

Issue 1872203005: Fix printf formats (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix unused param found by GC mole Created 4 years, 8 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
« no previous file with comments | « src/snapshot/serializer.cc ('k') | src/wasm/decoder.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_UTILS_H_ 5 #ifndef V8_UTILS_H_
6 #define V8_UTILS_H_ 6 #define V8_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <cmath> 11 #include <cmath>
12 12
13 #include "include/v8.h" 13 #include "include/v8.h"
14 #include "src/allocation.h" 14 #include "src/allocation.h"
15 #include "src/base/bits.h" 15 #include "src/base/bits.h"
16 #include "src/base/compiler-specific.h"
16 #include "src/base/logging.h" 17 #include "src/base/logging.h"
17 #include "src/base/macros.h" 18 #include "src/base/macros.h"
18 #include "src/base/platform/platform.h" 19 #include "src/base/platform/platform.h"
19 #include "src/globals.h" 20 #include "src/globals.h"
20 #include "src/list.h" 21 #include "src/list.h"
21 #include "src/vector.h" 22 #include "src/vector.h"
22 23
23 namespace v8 { 24 namespace v8 {
24 namespace internal { 25 namespace internal {
25 26
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 static const int kFirstBreakContinueToken = 3; 902 static const int kFirstBreakContinueToken = 3;
902 static const int kInvalidToken = -1; 903 static const int kInvalidToken = -1;
903 904
904 private: 905 private:
905 int next_token_ = kFirstBreakContinueToken; 906 int next_token_ = kFirstBreakContinueToken;
906 }; 907 };
907 908
908 // ---------------------------------------------------------------------------- 909 // ----------------------------------------------------------------------------
909 // I/O support. 910 // I/O support.
910 911
911 #if __GNUC__ >= 4
912 // On gcc we can ask the compiler to check the types of %d-style format
913 // specifiers and their associated arguments. TODO(erikcorry) fix this
914 // so it works on MacOSX.
915 #if defined(__MACH__) && defined(__APPLE__)
916 #define PRINTF_CHECKING
917 #define FPRINTF_CHECKING
918 #define PRINTF_METHOD_CHECKING
919 #define FPRINTF_METHOD_CHECKING
920 #else // MacOsX.
921 #define PRINTF_CHECKING __attribute__ ((format (printf, 1, 2)))
922 #define FPRINTF_CHECKING __attribute__ ((format (printf, 2, 3)))
923 #define PRINTF_METHOD_CHECKING __attribute__ ((format (printf, 2, 3)))
924 #define FPRINTF_METHOD_CHECKING __attribute__ ((format (printf, 3, 4)))
925 #endif
926 #else
927 #define PRINTF_CHECKING
928 #define FPRINTF_CHECKING
929 #define PRINTF_METHOD_CHECKING
930 #define FPRINTF_METHOD_CHECKING
931 #endif
932
933 // Our version of printf(). 912 // Our version of printf().
934 void PRINTF_CHECKING PrintF(const char* format, ...); 913 void PRINTF_FORMAT(1, 2) PrintF(const char* format, ...);
935 void FPRINTF_CHECKING PrintF(FILE* out, const char* format, ...); 914 void PRINTF_FORMAT(2, 3) PrintF(FILE* out, const char* format, ...);
936 915
937 // Prepends the current process ID to the output. 916 // Prepends the current process ID to the output.
938 void PRINTF_CHECKING PrintPID(const char* format, ...); 917 void PRINTF_FORMAT(1, 2) PrintPID(const char* format, ...);
939 918
940 // Prepends the current process ID and given isolate pointer to the output. 919 // Prepends the current process ID and given isolate pointer to the output.
941 void PrintIsolate(void* isolate, const char* format, ...); 920 void PRINTF_FORMAT(2, 3) PrintIsolate(void* isolate, const char* format, ...);
942 921
943 // Safe formatting print. Ensures that str is always null-terminated. 922 // Safe formatting print. Ensures that str is always null-terminated.
944 // Returns the number of chars written, or -1 if output was truncated. 923 // Returns the number of chars written, or -1 if output was truncated.
945 int FPRINTF_CHECKING SNPrintF(Vector<char> str, const char* format, ...); 924 int PRINTF_FORMAT(2, 3) SNPrintF(Vector<char> str, const char* format, ...);
946 int VSNPrintF(Vector<char> str, const char* format, va_list args); 925 int PRINTF_FORMAT(2, 0)
926 VSNPrintF(Vector<char> str, const char* format, va_list args);
947 927
948 void StrNCpy(Vector<char> dest, const char* src, size_t n); 928 void StrNCpy(Vector<char> dest, const char* src, size_t n);
949 929
950 // Our version of fflush. 930 // Our version of fflush.
951 void Flush(FILE* out); 931 void Flush(FILE* out);
952 932
953 inline void Flush() { 933 inline void Flush() {
954 Flush(stdout); 934 Flush(stdout);
955 } 935 }
956 936
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 #undef CASE 1419 #undef CASE
1440 #endif 1420 #endif
1441 1421
1442 1422
1443 class StringBuilder : public SimpleStringBuilder { 1423 class StringBuilder : public SimpleStringBuilder {
1444 public: 1424 public:
1445 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } 1425 explicit StringBuilder(int size) : SimpleStringBuilder(size) { }
1446 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } 1426 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { }
1447 1427
1448 // Add formatted contents to the builder just like printf(). 1428 // Add formatted contents to the builder just like printf().
1449 void AddFormatted(const char* format, ...); 1429 void PRINTF_FORMAT(2, 3) AddFormatted(const char* format, ...);
1450 1430
1451 // Add formatted contents like printf based on a va_list. 1431 // Add formatted contents like printf based on a va_list.
1452 void AddFormattedList(const char* format, va_list list); 1432 void PRINTF_FORMAT(2, 0) AddFormattedList(const char* format, va_list list);
1433
1453 private: 1434 private:
1454 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); 1435 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
1455 }; 1436 };
1456 1437
1457 1438
1458 bool DoubleToBoolean(double d); 1439 bool DoubleToBoolean(double d);
1459 1440
1460 template <typename Stream> 1441 template <typename Stream>
1461 bool StringToArrayIndex(Stream* stream, uint32_t* index) { 1442 bool StringToArrayIndex(Stream* stream, uint32_t* index) {
1462 uint16_t ch = stream->GetNext(); 1443 uint16_t ch = stream->GetNext();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 } 1516 }
1536 1517
1537 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { 1518 static inline void WriteUnalignedUInt32(void* p, uint32_t value) {
1538 WriteUnalignedValue(p, value); 1519 WriteUnalignedValue(p, value);
1539 } 1520 }
1540 1521
1541 } // namespace internal 1522 } // namespace internal
1542 } // namespace v8 1523 } // namespace v8
1543 1524
1544 #endif // V8_UTILS_H_ 1525 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/snapshot/serializer.cc ('k') | src/wasm/decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698