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

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

Issue 1514083002: Fix intermittent GrAutoLocaleSetter crashes on Windows (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comment 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)
14 #include "SkString.h"
15 #endif
16
13 #if !defined(SK_BUILD_FOR_ANDROID) 17 #if !defined(SK_BUILD_FOR_ANDROID)
14 #include <locale.h> 18 #include <locale.h>
15 #endif 19 #endif
16 20
17 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
18 #include <xlocale.h> 22 #include <xlocale.h>
19 #endif 23 #endif
20 24
21 /** 25 /**
22 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android 26 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android
23 * doesn't support locale in the NDK, so this is a no-op there. 27 * doesn't support locale in the NDK, so this is a no-op there.
24 */ 28 */
25 class GrAutoLocaleSetter : public SkNoncopyable { 29 class GrAutoLocaleSetter : public SkNoncopyable {
26 public: 30 public:
27 GrAutoLocaleSetter (const char* name) { 31 GrAutoLocaleSetter (const char* name) {
28 #if defined(SK_BUILD_FOR_WIN) 32 #if defined(SK_BUILD_FOR_WIN)
29 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); 33 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
30 fOldLocale = setlocale(LC_ALL, name); 34 char* oldLocale = setlocale(LC_ALL, name);
35 if (oldLocale) {
36 fOldLocale = oldLocale;
37 fShouldRestoreLocale = true;
38 } else {
39 fShouldRestoreLocale = false;
40 }
31 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 41 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
32 fLocale = newlocale(LC_ALL, name, 0); 42 fLocale = newlocale(LC_ALL, name, 0);
33 if (fLocale) { 43 if (fLocale) {
34 fOldLocale = uselocale(fLocale); 44 fOldLocale = uselocale(fLocale);
35 } else { 45 } else {
36 fOldLocale = static_cast<locale_t>(0); 46 fOldLocale = static_cast<locale_t>(0);
37 } 47 }
38 #else 48 #else
39 (void) name; // suppress unused param warning. 49 (void) name; // suppress unused param warning.
40 #endif 50 #endif
41 } 51 }
42 52
43 ~GrAutoLocaleSetter () { 53 ~GrAutoLocaleSetter () {
44 #if defined(SK_BUILD_FOR_WIN) 54 #if defined(SK_BUILD_FOR_WIN)
45 if (fOldLocale) { 55 if (fShouldRestoreLocale) {
46 setlocale(LC_ALL, fOldLocale); 56 setlocale(LC_ALL, fOldLocale.c_str());
47 } 57 }
48 _configthreadlocale(fOldPerThreadLocale); 58 _configthreadlocale(fOldPerThreadLocale);
49 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 59 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
50 if (fLocale) { 60 if (fLocale) {
51 uselocale(fOldLocale); 61 uselocale(fOldLocale);
52 freelocale(fLocale); 62 freelocale(fLocale);
53 } 63 }
54 #endif 64 #endif
55 } 65 }
56 66
57 private: 67 private:
58 #if defined(SK_BUILD_FOR_WIN) 68 #if defined(SK_BUILD_FOR_WIN)
59 int fOldPerThreadLocale; 69 int fOldPerThreadLocale;
60 const char* fOldLocale; 70 bool fShouldRestoreLocale;
71 SkString fOldLocale;
61 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) 72 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
62 locale_t fOldLocale; 73 locale_t fOldLocale;
63 locale_t fLocale; 74 locale_t fLocale;
64 #endif 75 #endif
65 }; 76 };
66 77
67 #endif 78 #endif
68 79
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