MCPcopy Create free account
hub / github.com/apache/thrift / printf

Method printf

lib/cpp/src/thrift/TOutput.cpp:36–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34TOutput::TOutput() : f_(&errorTimeWrapper) {}
35
36void TOutput::printf(const char* message, ...) {
37#ifndef THRIFT_SQUELCH_CONSOLE_OUTPUT
38 // Try to reduce heap usage, even if printf is called rarely.
39 static const int STACK_BUF_SIZE = 256;
40 char stack_buf[STACK_BUF_SIZE];
41 va_list ap;
42
43#ifdef _MSC_VER
44 va_start(ap, message);
45 int need = _vscprintf(message, ap);
46 va_end(ap);
47
48 if (need < STACK_BUF_SIZE) {
49 va_start(ap, message);
50 vsnprintf_s(stack_buf, STACK_BUF_SIZE, _TRUNCATE, message, ap);
51 va_end(ap);
52 f_(stack_buf);
53 return;
54 }
55#else
56 va_start(ap, message);
57 int need = vsnprintf(stack_buf, STACK_BUF_SIZE, message, ap);
58 va_end(ap);
59
60 if (need < STACK_BUF_SIZE) {
61 f_(stack_buf);
62 return;
63 }
64#endif
65
66 char* heap_buf = (char*)malloc((need + 1) * sizeof(char));
67 if (heap_buf == nullptr) {
68#ifdef _MSC_VER
69 va_start(ap, message);
70 vsnprintf_s(stack_buf, STACK_BUF_SIZE, _TRUNCATE, message, ap);
71 va_end(ap);
72#endif
73 // Malloc failed. We might as well print the stack buffer.
74 f_(stack_buf);
75 return;
76 }
77
78 va_start(ap, message);
79 int rval = vsnprintf(heap_buf, need + 1, message, ap);
80 va_end(ap);
81 // TODO(shigin): inform user
82 if (rval != -1) {
83 f_(heap_buf);
84 }
85 free(heap_buf);
86#else
87 THRIFT_UNUSED_VARIABLE(message);
88#endif
89}
90
91void TOutput::errorTimeWrapper(const char* msg) {
92#ifndef THRIFT_SQUELCH_CONSOLE_OUTPUT

Callers 15

runMethod · 0.80
exceptionTestMethod · 0.80
multiExceptionTestMethod · 0.80
~ServerThreadMethod · 0.80
processMethod · 0.80
processFastMethod · 0.80
processMethod · 0.80
listenMethod · 0.80
readMethod · 0.80
resetOutputFileMethod · 0.80
closeMethod · 0.80
listenMethod · 0.80

Calls

no outgoing calls

Tested by 8

runMethod · 0.64
exceptionTestMethod · 0.64
multiExceptionTestMethod · 0.64
~ServerThreadMethod · 0.64
mainMethod · 0.64
onErrorMethod · 0.64
mainMethod · 0.64
onCompleteMethod · 0.64