blob: 144b28a4a3b3ae61ead92ce4322d969f400e4188 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
|