Allow printf-style formatting to be used in SK_ABORT.
(This is a simple reland of https://skia-review.googlesource.com/c/skia/+/293272 and is functionally unchanged, but needed to be reconstructed manually because JavaInputStreamAdaptor.cpp was deleted.) SK_ABORT was already using SkDebugf to print the error message to the console, so all the moving parts were there. This CL just adds a mechanism for the calling code to pass in arguments. Added a use case to demonstrate usage--when an allocation fails, the requested size is now shown in the error message. Change-Id: If8600a9febad15b7c8b7a04479a1d92442521f21 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294705 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
ac16760df4
commit
616da104ab
@ -61,9 +61,8 @@ public:
|
||||
void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
|
||||
int* startVertex) override {
|
||||
if (vertexSize * vertexCount > sizeof(fStaticVertexData)) {
|
||||
SK_ABORT(SkStringPrintf(
|
||||
"FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
|
||||
vertexSize * vertexCount, SK_ARRAY_COUNT(fStaticVertexData)).c_str());
|
||||
SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
|
||||
vertexSize * vertexCount, SK_ARRAY_COUNT(fStaticVertexData));
|
||||
}
|
||||
*startVertex = 0;
|
||||
return fStaticVertexData;
|
||||
@ -73,9 +72,8 @@ public:
|
||||
int drawCount, sk_sp<const GrBuffer>* buffer, size_t* offsetInBytes) override {
|
||||
int staticBufferCount = (int)SK_ARRAY_COUNT(fStaticDrawIndexedIndirectData);
|
||||
if (drawCount > staticBufferCount) {
|
||||
SK_ABORT(SkStringPrintf(
|
||||
"FATAL: wanted %i static drawIndexedIndirect elements; only have %i.\n",
|
||||
drawCount, staticBufferCount).c_str());
|
||||
SK_ABORT("FATAL: wanted %i static drawIndexedIndirect elements; only have %i.\n",
|
||||
drawCount, staticBufferCount);
|
||||
}
|
||||
return fStaticDrawIndexedIndirectData;
|
||||
}
|
||||
|
@ -279,22 +279,20 @@
|
||||
# define SK_DUMP_GOOGLE3_STACK()
|
||||
#endif
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
// Lets visual studio follow error back to source
|
||||
#define SK_DUMP_LINE_FORMAT(message) \
|
||||
SkDebugf("%s(%d): fatal error: \"%s\"\n", __FILE__, __LINE__, message)
|
||||
#else
|
||||
#define SK_DUMP_LINE_FORMAT(message) \
|
||||
SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, message)
|
||||
#endif
|
||||
|
||||
#ifndef SK_ABORT
|
||||
# define SK_ABORT(message) \
|
||||
# ifdef SK_BUILD_FOR_WIN
|
||||
// This style lets Visual Studio follow errors back to the source file.
|
||||
# define SK_DUMP_LINE_FORMAT "%s(%d)"
|
||||
# else
|
||||
# define SK_DUMP_LINE_FORMAT "%s:%d"
|
||||
# endif
|
||||
# define SK_ABORT(message, ...) \
|
||||
do { \
|
||||
SK_DUMP_LINE_FORMAT(message); \
|
||||
SK_DUMP_GOOGLE3_STACK(); \
|
||||
sk_abort_no_print(); \
|
||||
SkUNREACHABLE; \
|
||||
SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \
|
||||
__FILE__, __LINE__, ##__VA_ARGS__); \
|
||||
SK_DUMP_GOOGLE3_STACK(); \
|
||||
sk_abort_no_print(); \
|
||||
SkUNREACHABLE; \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
@ -450,16 +448,16 @@ SK_API extern void sk_abort_no_print(void);
|
||||
// x - 4;
|
||||
// }
|
||||
#define SkASSERT_RELEASE(cond) \
|
||||
static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(" #cond ")"); }() )
|
||||
static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() )
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
#define SkASSERT(cond) SkASSERT_RELEASE(cond)
|
||||
#define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \
|
||||
SkDebugf(fmt"\n", __VA_ARGS__); \
|
||||
SK_ABORT("assert(" #cond ")"); \
|
||||
SK_ABORT("assert(%s)", #cond); \
|
||||
}() )
|
||||
#define SkDEBUGFAIL(message) SK_ABORT(message)
|
||||
#define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
|
||||
#define SkDEBUGFAIL(message) SK_ABORT("%s", message)
|
||||
#define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__)
|
||||
#define SkDEBUGCODE(...) __VA_ARGS__
|
||||
#define SkDEBUGF(...) SkDebugf(__VA_ARGS__)
|
||||
#define SkAssertResult(cond) SkASSERT(cond)
|
||||
|
@ -436,7 +436,7 @@ GrBlockAllocator::ByteRange GrBlockAllocator::allocate(size_t size) {
|
||||
<= std::numeric_limits<int32_t>::max());
|
||||
|
||||
if (size > kMaxAllocationSize) {
|
||||
SK_ABORT("Allocation too large");
|
||||
SK_ABORT("Allocation too large (%zu bytes requested)", size);
|
||||
}
|
||||
|
||||
int iSize = (int) size;
|
||||
|
@ -60,7 +60,7 @@ static GpuPathRenderers get_named_pathrenderers_flags(const char* name) {
|
||||
} else if (!strcmp(name, "default")) {
|
||||
return GpuPathRenderers::kDefault;
|
||||
}
|
||||
SK_ABORT(SkStringPrintf("error: unknown named path renderer \"%s\"\n", name).c_str());
|
||||
SK_ABORT("error: unknown named path renderer \"%s\"\n", name);
|
||||
}
|
||||
|
||||
static GpuPathRenderers collect_gpu_path_renderers_from_flags() {
|
||||
|
@ -573,7 +573,7 @@ int main(int argc, char** argv) {
|
||||
case Result::Ok: break;
|
||||
case Result::Skip: return false;
|
||||
case Result::Fail:
|
||||
SK_ABORT(result.failure.c_str());
|
||||
SK_ABORT("%s", result.failure.c_str());
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user