aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/private/SkSafe_math.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
commita87508008dfa1604baf2d4e39bf44704c00f261c (patch)
tree0be2ade96772037a02803b30e157c367d931e3d9 /src/deps/skia/include/private/SkSafe_math.h
parent4a19a3f07f1887903e5638a3be167f0c7b377ba3 (diff)
downloadbun-jarred/canvas.tar.gz
bun-jarred/canvas.tar.zst
bun-jarred/canvas.zip
Diffstat (limited to 'src/deps/skia/include/private/SkSafe_math.h')
-rw-r--r--src/deps/skia/include/private/SkSafe_math.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/deps/skia/include/private/SkSafe_math.h b/src/deps/skia/include/private/SkSafe_math.h
new file mode 100644
index 000000000..144b28a4a
--- /dev/null
+++ b/src/deps/skia/include/private/SkSafe_math.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSafe_math_DEFINED
+#define SkSafe_math_DEFINED
+
+// This file protects against known bugs in ucrt\math.h.
+// Namely, that header defines inline methods without marking them static,
+// which makes it very easy to cause ODR violations and ensuing chaos.
+//
+// TODO: other headers? Here are some potential problem headers:
+// $ grep -R __inline * | grep -v static | cut -f 1 -d: | sort | uniq
+// corecrt.h
+// corecrt_stdio_config.h
+// ctype.h
+// fenv.h
+// locale.h
+// malloc.h
+// math.h
+// tchar.h
+// wchar.h
+// I took a quick look through other headers outside math.h.
+// Nothing looks anywhere near as likely to be used by Skia as math.h.
+
+#if defined(_MSC_VER) && !defined(_INC_MATH)
+ // Our strategy here is to simply inject "static" into the headers
+ // where it should have been written, just before __inline.
+ //
+ // Most inline-but-not-static methods in math.h are 32-bit only,
+ // but not all of them (see frexpf, hypothf, ldexpf...). So to
+ // be safe, 32- and 64-bit builds both get this treatment.
+
+ #define __inline static __inline
+ #include <math.h>
+ #undef __inline
+
+ #if !defined(_INC_MATH)
+ #error Hmm. Looks like math.h has changed its header guards.
+ #endif
+
+ #define INC_MATH_IS_SAFE_NOW
+
+#else
+ #include <math.h>
+
+#endif
+
+#endif//SkSafe_math_DEFINED