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

Side by Side Diff: src/gpu/GrAutoLocaleSetter.h

Issue 1526703003: Porting Skia for newlib compatibility. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrAutoLocaleSetter_DEFINED 8 #ifndef GrAutoLocaleSetter_DEFINED
9 #define GrAutoLocaleSetter_DEFINED 9 #define GrAutoLocaleSetter_DEFINED
10 10
11 #include "GrTypes.h" 11 #include "GrTypes.h"
12 12
13 #if defined(SK_BUILD_FOR_WIN) 13 #if defined(SK_BUILD_FOR_WIN)
14 #include "SkString.h" 14 #include "SkString.h"
15 #endif 15 #endif
16 16
17 #if !defined(SK_BUILD_FOR_ANDROID) 17 #if !defined(SK_BUILD_FOR_ANDROID)
18 #include <locale.h> 18 #include <locale.h>
19 #endif 19 #endif
20 20
21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
22 #include <xlocale.h> 22 #include <xlocale.h>
23 #endif 23 #endif
24 24
25 #if defined(SK_BUILD_FOR_ANDROID) || defined(__UCLIBC__) || \
mtklein 2015/12/15 13:42:58 Skia typically wraps at column 100, so I bet this'
Sean Klein 2015/12/15 17:20:26 Done.
26 defined(_NEWLIB_VERSION)
27 #define HAVE_LOCALE_T 0
mtklein 2015/12/15 13:42:58 We tend to indent inside #if blocks, but for somet
Sean Klein 2015/12/15 17:20:26 Acknowledged.
28 #else
29 #define HAVE_LOCALE_T 1
30 #endif
31
25 /** 32 /**
26 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android 33 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android
27 * doesn't support locale in the NDK, so this is a no-op there. 34 * doesn't support locale in the NDK, so this is a no-op there.
28 */ 35 */
29 class GrAutoLocaleSetter : public SkNoncopyable { 36 class GrAutoLocaleSetter : public SkNoncopyable {
30 public: 37 public:
31 GrAutoLocaleSetter (const char* name) { 38 GrAutoLocaleSetter (const char* name) {
32 #if defined(SK_BUILD_FOR_WIN) 39 #if defined(SK_BUILD_FOR_WIN)
33 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); 40 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
34 char* oldLocale = setlocale(LC_ALL, name); 41 char* oldLocale = setlocale(LC_ALL, name);
35 if (oldLocale) { 42 if (oldLocale) {
36 fOldLocale = oldLocale; 43 fOldLocale = oldLocale;
37 fShouldRestoreLocale = true; 44 fShouldRestoreLocale = true;
38 } else { 45 } else {
39 fShouldRestoreLocale = false; 46 fShouldRestoreLocale = false;
40 } 47 }
41 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 48 #elif HAVE_LOCALE_T
42 fLocale = newlocale(LC_ALL, name, 0); 49 fLocale = newlocale(LC_ALL, name, 0);
43 if (fLocale) { 50 if (fLocale) {
44 fOldLocale = uselocale(fLocale); 51 fOldLocale = uselocale(fLocale);
45 } else { 52 } else {
46 fOldLocale = static_cast<locale_t>(0); 53 fOldLocale = static_cast<locale_t>(0);
47 } 54 }
48 #else 55 #else
49 (void) name; // suppress unused param warning. 56 (void) name; // suppress unused param warning.
50 #endif 57 #endif
51 } 58 }
52 59
53 ~GrAutoLocaleSetter () { 60 ~GrAutoLocaleSetter () {
54 #if defined(SK_BUILD_FOR_WIN) 61 #if defined(SK_BUILD_FOR_WIN)
55 if (fShouldRestoreLocale) { 62 if (fShouldRestoreLocale) {
56 setlocale(LC_ALL, fOldLocale.c_str()); 63 setlocale(LC_ALL, fOldLocale.c_str());
57 } 64 }
58 _configthreadlocale(fOldPerThreadLocale); 65 _configthreadlocale(fOldPerThreadLocale);
59 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 66 #elif HAVE_LOCALE_T
60 if (fLocale) { 67 if (fLocale) {
61 uselocale(fOldLocale); 68 uselocale(fOldLocale);
62 freelocale(fLocale); 69 freelocale(fLocale);
63 } 70 }
64 #endif 71 #endif
65 } 72 }
66 73
67 private: 74 private:
68 #if defined(SK_BUILD_FOR_WIN) 75 #if defined(SK_BUILD_FOR_WIN)
69 int fOldPerThreadLocale; 76 int fOldPerThreadLocale;
70 bool fShouldRestoreLocale; 77 bool fShouldRestoreLocale;
71 SkString fOldLocale; 78 SkString fOldLocale;
72 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 79 #elif HAVE_LOCALE_T
73 locale_t fOldLocale; 80 locale_t fOldLocale;
74 locale_t fLocale; 81 locale_t fLocale;
75 #endif 82 #endif
mtklein 2015/12/15 13:42:58 Given that this is a header, let's #undef HAVE_LOC
Sean Klein 2015/12/15 17:20:26 Done.
76 }; 83 };
77 84
78 #endif 85 #endif
79 86
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698