WebKit Bugzilla
Attachment 361353 Details for
Bug 192405
: [WTF] Add environment variable helpers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proof of concept
bug-192405-20190206180005.patch (text/plain), 29.02 KB, created by
Ross Kirsling
on 2019-02-06 18:00:06 PST
(
hide
)
Description:
Proof of concept
Filename:
MIME Type:
Creator:
Ross Kirsling
Created:
2019-02-06 18:00:06 PST
Size:
29.02 KB
patch
obsolete
>Subversion Revision: 241044 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 9477d74c1095fe02b00d2d2751e18b3b718745db..68a90f30dd440ff6d13450bd051b0e87c97fda40 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,25 @@ >+2019-02-06 Ross Kirsling <ross.kirsling@sony.com> >+ >+ [WTF] Add environment variable helpers >+ https://bugs.webkit.org/show_bug.cgi?id=192405 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * inspector/remote/glib/RemoteInspectorGlib.cpp: >+ (Inspector::RemoteInspector::RemoteInspector): >+ (Inspector::RemoteInspector::start): >+ * jsc.cpp: >+ (startTimeoutThreadIfNeeded): >+ * runtime/Options.cpp: >+ (JSC::overrideOptionWithHeuristic): >+ (JSC::Options::overrideAliasedOptionWithHeuristic): >+ (JSC::Options::initialize): >+ * runtime/VM.cpp: >+ (JSC::enableAssembler): >+ (JSC::VM::VM): >+ * tools/CodeProfiling.cpp: >+ (JSC::CodeProfiling::notifyAllocator): >+ > 2019-02-06 Yusuke Suzuki <ysuzuki@apple.com> > > [JSC] Unify indirectEvalExecutableSpace and directEvalExecutableSpace >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 65684330426e758849b51e259223d37e3270e59e..c44890cfc8a0e83bf8a13c095745671c37002e6a 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,29 @@ >+2019-02-06 Ross Kirsling <ross.kirsling@sony.com> >+ >+ [WTF] Add environment variable helpers >+ https://bugs.webkit.org/show_bug.cgi?id=192405 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * WTF.xcodeproj/project.pbxproj: >+ * wtf/CMakeLists.txt: >+ * wtf/Environment.h: Added. >+ * wtf/PlatformGTK.cmake: >+ * wtf/PlatformJSCOnly.cmake: >+ * wtf/PlatformMac.cmake: >+ * wtf/PlatformPlayStation.cmake: >+ * wtf/PlatformWPE.cmake: >+ * wtf/PlatformWin.cmake: >+ * wtf/generic/EnvironmentGeneric.cpp: Added. >+ * wtf/glib/EnvironmentGlib.cpp: Added. >+ >+ * wtf/DataLog.cpp: >+ (WTF::initializeLogFileOnce): >+ * wtf/NumberOfCores.cpp: >+ (WTF::numberOfProcessorCores): >+ * wtf/posix/FileSystemPOSIX.cpp: >+ (WTF::FileSystemImpl::openTemporaryFile): >+ > 2019-02-05 Keith Rollin <krollin@apple.com> > > Enable the automatic checking and regenerations of .xcfilelists during builds >diff --git a/Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorGlib.cpp b/Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorGlib.cpp >index b73455a40cc15d56353ff694fb65340182924c48..cd4072f4c99e6c18f5bf7758d6a8bd455e169972 100644 >--- a/Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorGlib.cpp >+++ b/Source/JavaScriptCore/inspector/remote/glib/RemoteInspectorGlib.cpp >@@ -32,6 +32,7 @@ > #include "RemoteConnectionToTarget.h" > #include "RemoteInspectionTarget.h" > #include <gio/gio.h> >+#include <wtf/Environment.h> > #include <wtf/NeverDestroyed.h> > #include <wtf/RunLoop.h> > #include <wtf/glib/GUniquePtr.h> >@@ -51,7 +52,7 @@ RemoteInspector& RemoteInspector::singleton() > > RemoteInspector::RemoteInspector() > { >- if (g_getenv("WEBKIT_INSPECTOR_SERVER")) >+ if (!!Environment::get("WEBKIT_INSPECTOR_SERVER")) > start(); > } > >@@ -65,7 +66,8 @@ void RemoteInspector::start() > m_enabled = true; > m_cancellable = adoptGRef(g_cancellable_new()); > >- GUniquePtr<char> inspectorAddress(g_strdup(g_getenv("WEBKIT_INSPECTOR_SERVER"))); >+ auto inspectorServerString = Environment::get("WEBKIT_INSPECTOR_SERVER").utf8().data(); >+ GUniquePtr<char> inspectorAddress(g_strdup(inspectorServerString)); > char* portPtr = g_strrstr(inspectorAddress.get(), ":"); > ASSERT(portPtr); > *portPtr = '\0'; >@@ -79,7 +81,7 @@ void RemoteInspector::start() > if (GRefPtr<GDBusConnection> connection = adoptGRef(g_dbus_connection_new_for_address_finish(result, &error.outPtr()))) > inspector->setupConnection(WTFMove(connection)); > else if (!g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED)) >- WTFLogAlways("RemoteInspector failed to connect to inspector server at: %s: %s", g_getenv("WEBKIT_INSPECTOR_SERVER"), error->message); >+ WTFLogAlways("RemoteInspector failed to connect to inspector server at: %s: %s", inspectorServerString, error->message); > }, this); > } > >diff --git a/Source/JavaScriptCore/jsc.cpp b/Source/JavaScriptCore/jsc.cpp >index be0180605e6e8abf48ab711b86c9d4fc98c05f1a..a21ac0eaf1cc2e9c3c7dae2cb3491267eef18109 100644 >--- a/Source/JavaScriptCore/jsc.cpp >+++ b/Source/JavaScriptCore/jsc.cpp >@@ -83,6 +83,7 @@ > #include <type_traits> > #include <wtf/Box.h> > #include <wtf/CommaPrinter.h> >+#include <wtf/Environment.h> > #include <wtf/MainThread.h> > #include <wtf/MemoryPressureHandler.h> > #include <wtf/MonotonicTime.h> >@@ -2250,8 +2251,11 @@ static double s_timeoutMultiplier = 1.0; > > static void startTimeoutThreadIfNeeded() > { >- if (char* timeoutString = getenv("JSCTEST_timeout")) { >- if (sscanf(timeoutString, "%lf", &s_desiredTimeout) != 1) { >+ auto timeoutString = Environment::get("JSCTEST_timeout"); >+ if (!!timeoutString) { >+ bool ok; >+ s_desiredTimeout = timeoutString.toDouble(&ok); >+ if (!ok) { > dataLog("WARNING: timeout string is malformed, got ", timeoutString, > " but expected a number. Not using a timeout.\n"); > } else { >diff --git a/Source/JavaScriptCore/runtime/Options.cpp b/Source/JavaScriptCore/runtime/Options.cpp >index 84d7326a24fbe5a5de03c5c38dbf2bdedf2360cb..df114b47e327a11c4b76246ead4ac4e46ce98b69 100644 >--- a/Source/JavaScriptCore/runtime/Options.cpp >+++ b/Source/JavaScriptCore/runtime/Options.cpp >@@ -39,6 +39,7 @@ > #include <wtf/ASCIICType.h> > #include <wtf/Compiler.h> > #include <wtf/DataLog.h> >+#include <wtf/Environment.h> > #include <wtf/NumberOfCores.h> > #include <wtf/PointerPreparations.h> > #include <wtf/StdLibExtras.h> >@@ -176,7 +177,7 @@ bool overrideOptionWithHeuristic(T& variable, Options::ID id, const char* name, > bool available = (availability == Options::Availability::Normal) > || Options::isAvailable(id, availability); > >- const char* stringValue = getenv(name); >+ auto stringValue = Environment::get(name).utf8().data(); > if (!stringValue) > return false; > >@@ -189,7 +190,7 @@ bool overrideOptionWithHeuristic(T& variable, Options::ID id, const char* name, > > bool Options::overrideAliasedOptionWithHeuristic(const char* name) > { >- const char* stringValue = getenv(name); >+ auto stringValue = Environment::get(name).utf8().data(); > if (!stringValue) > return false; > >@@ -597,9 +598,8 @@ void Options::initialize() > > #if ASAN_ENABLED && OS(LINUX) && ENABLE(WEBASSEMBLY_FAST_MEMORY) > if (Options::useWebAssemblyFastMemory()) { >- const char* asanOptions = getenv("ASAN_OPTIONS"); >- bool okToUseWebAssemblyFastMemory = asanOptions >- && (strstr(asanOptions, "allow_user_segv_handler=1") || strstr(asanOptions, "handle_segv=0")); >+ auto asanOptions = Environment::get("ASAN_OPTIONS"); >+ bool okToUseWebAssemblyFastMemory = asanOptions.contains("allow_user_segv_handler=1") || asanOptions.contains("handle_segv=0"); > if (!okToUseWebAssemblyFastMemory) { > dataLogLn("WARNING: ASAN interferes with JSC signal handlers; useWebAssemblyFastMemory will be disabled."); > Options::useWebAssemblyFastMemory() = false; >diff --git a/Source/JavaScriptCore/runtime/VM.cpp b/Source/JavaScriptCore/runtime/VM.cpp >index a3091d09693f89c8355e4cde07d87c8cb3d3b9fe..06b94ca212249e37773ef5f979d5a5bcae4b8fa4 100644 >--- a/Source/JavaScriptCore/runtime/VM.cpp >+++ b/Source/JavaScriptCore/runtime/VM.cpp >@@ -149,6 +149,7 @@ > #include "WeakGCMapInlines.h" > #include "WebAssemblyFunction.h" > #include "WebAssemblyWrapperFunction.h" >+#include <wtf/Environment.h> > #include <wtf/ProcessID.h> > #include <wtf/ReadWriteLock.h> > #include <wtf/SimpleStats.h> >@@ -197,8 +198,8 @@ static bool enableAssembler(ExecutableAllocator& executableAllocator) > return false; > } > >- char* canUseJITString = getenv("JavaScriptCoreUseJIT"); >- return !canUseJITString || atoi(canUseJITString); >+ auto canUseJITString = Environment::get("JavaScriptCoreUseJIT"); >+ return !canUseJITString || canUseJITString.toInt(); > } > #endif // ENABLE(!ASSEMBLER) > >@@ -428,7 +429,7 @@ VM::VM(VMType vmType, HeapType heapType) > m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*this); > > StringPrintStream pathOut; >- const char* profilerPath = getenv("JSC_PROFILER_PATH"); >+ auto profilerPath = Environment::get("JSC_PROFILER_PATH").utf8().data(); > if (profilerPath) > pathOut.print(profilerPath, "/"); > pathOut.print("JSCProfile-", getCurrentProcessID(), "-", m_perBytecodeProfiler->databaseID(), ".json"); >diff --git a/Source/JavaScriptCore/tools/CodeProfiling.cpp b/Source/JavaScriptCore/tools/CodeProfiling.cpp >index 94ebe8e2ca7e189f8f6d8d5f64d90f9d061c97df..6c1ceac92ffd2d595fcd1c65d55cf0a2cd583eb2 100644 >--- a/Source/JavaScriptCore/tools/CodeProfiling.cpp >+++ b/Source/JavaScriptCore/tools/CodeProfiling.cpp >@@ -28,6 +28,7 @@ > > #include "CodeProfile.h" > #include "MachineContext.h" >+#include <wtf/Environment.h> > #include <wtf/MetaAllocator.h> > > #if HAVE(SIGNAL_H) >@@ -85,21 +86,23 @@ void CodeProfiling::sample(void* pc, void** framePointer) > void CodeProfiling::notifyAllocator(WTF::MetaAllocator* allocator) > { > // Check for JSC_CODE_PROFILING. >- const char* codeProfilingMode = getenv("JSC_CODE_PROFILING"); >- if (!codeProfilingMode) >+ auto codeProfilingModeString = Environment::get("JSC_CODE_PROFILING"); >+ if (!codeProfilingModeString) > return; > > // Check for a valid mode, currently "1", "2", or "3". >- if (!codeProfilingMode[0] || codeProfilingMode[1]) >+ bool ok; >+ auto codeProfilingMode = codeProfilingModeString.toUInt(&ok); >+ if (!ok) > return; >- switch (*codeProfilingMode) { >- case '1': >+ switch (codeProfilingMode) { >+ case 1: > s_mode = Enabled; > break; >- case '2': >+ case 2: > s_mode = Verbose; > break; >- case '3': >+ case 3: > s_mode = VeryVerbose; > break; > default: >diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj >index e54641d892cbbba8ec8d580cc6cb807d11a4b598..e5c39c8dae934b91050cf4e2dfb2ad6c7b0ff356 100644 >--- a/Source/WTF/WTF.xcodeproj/project.pbxproj >+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj >@@ -95,6 +95,7 @@ > A331D95F21F249F6009F02AA /* FileSystemCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A331D95E21F249F6009F02AA /* FileSystemCocoa.mm */; }; > A331D96121F24A0A009F02AA /* FileSystemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A331D96021F24A0A009F02AA /* FileSystemMac.mm */; }; > A331D96721F24ABD009F02AA /* FileSystemPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A331D96621F24ABD009F02AA /* FileSystemPOSIX.cpp */; }; >+ A36FC643220BBCE9005E3C37 /* EnvironmentGeneric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A36FC642220BBCE9005E3C37 /* EnvironmentGeneric.cpp */; }; > A3B725EC987446AD93F1A440 /* RandomDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C8F597CA2A57417FBAB92FD6 /* RandomDevice.cpp */; }; > A3E4DD931F3A803400DED0B4 /* TextStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3E4DD911F3A803400DED0B4 /* TextStream.cpp */; }; > A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3EE5C3921FFAC5E00FABD61 /* OSAllocatorPOSIX.cpp */; }; >@@ -448,6 +449,8 @@ > A331D96021F24A0A009F02AA /* FileSystemMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSystemMac.mm; sourceTree = "<group>"; }; > A331D96621F24ABD009F02AA /* FileSystemPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemPOSIX.cpp; sourceTree = "<group>"; }; > A36E16F7216FF828008DD87E /* WTFSemaphore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFSemaphore.h; sourceTree = "<group>"; }; >+ A36FC640220BBC9F005E3C37 /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; }; >+ A36FC642220BBCE9005E3C37 /* EnvironmentGeneric.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentGeneric.cpp; sourceTree = "<group>"; }; > A3AB6E6A1F3E1AD6009C14B1 /* ValueToString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValueToString.h; sourceTree = "<group>"; }; > A3D273B921F2EE9100866971 /* MetadataSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MetadataSPI.h; sourceTree = "<group>"; }; > A3E4DD911F3A803400DED0B4 /* TextStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextStream.cpp; sourceTree = "<group>"; }; >@@ -807,6 +810,14 @@ > path = posix; > sourceTree = "<group>"; > }; >+ A36FC641220BBCB7005E3C37 /* generic */ = { >+ isa = PBXGroup; >+ children = ( >+ A36FC642220BBCE9005E3C37 /* EnvironmentGeneric.cpp */, >+ ); >+ path = generic; >+ sourceTree = "<group>"; >+ }; > A3D273B821F2EE7B00866971 /* mac */ = { > isa = PBXGroup; > children = ( >@@ -845,6 +856,7 @@ > E4A0AD3B1A96251900536DF6 /* cocoa */, > 37C7CC281EA40A54007BD956 /* darwin */, > A8A47281151A825A004123FF /* dtoa */, >+ A36FC641220BBCB7005E3C37 /* generic */, > 1FA47C87152502DA00568D1B /* ios */, > A8A472C4151A825A004123FF /* mac */, > E43A46851E228B5700276B05 /* persistence */, >@@ -929,6 +941,7 @@ > FE05FAE61FDB214300093230 /* DumbPtrTraits.h */, > AD653DA82006B6C200D820D7 /* DumbValueTraits.h */, > 1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */, >+ A36FC640220BBC9F005E3C37 /* Environment.h */, > AD7C434A1DD2A4A70026888B /* Expected.h */, > A8A4729F151A825A004123FF /* ExportMacros.h */, > 0F7C5FB51D885CF20044F5E2 /* FastBitVector.cpp */, >@@ -1026,8 +1039,6 @@ > A8A472CE151A825B004123FF /* MetaAllocator.h */, > A8A472CF151A825B004123FF /* MetaAllocatorHandle.h */, > FE7497ED209163060003565B /* MetaAllocatorPtr.h */, >- 5FAD3AE121B9636600BEE178 /* URLHelpers.cpp */, >- 5FAD3AE021B9636600BEE178 /* URLHelpers.h */, > 0F66B2821DC97BAB004A1D3F /* MonotonicTime.cpp */, > 0F66B2831DC97BAB004A1D3F /* MonotonicTime.h */, > FE8225301B2A1E5B00BA68FD /* NakedPtr.h */, >@@ -1175,6 +1186,8 @@ > 5CC0EE7121629F1800A1A842 /* URL.h */, > 5C1F0597216439940039302C /* URLHash.h */, > 5CC0EE772162A01000A1A842 /* URLHash.h */, >+ 5FAD3AE121B9636600BEE178 /* URLHelpers.cpp */, >+ 5FAD3AE021B9636600BEE178 /* URLHelpers.h */, > 5CC0EE7321629F1900A1A842 /* URLParser.cpp */, > 5CC0EE7221629F1900A1A842 /* URLParser.h */, > 7AFEC6B01EB22B5900DADE36 /* UUID.cpp */, >@@ -1520,6 +1533,7 @@ > A8A473B0151A825B004123FF /* double-conversion.cc in Sources */, > A8A473BA151A825B004123FF /* dtoa.cpp in Sources */, > 143DDE9620C8BC37007F76FA /* Entitlements.mm in Sources */, >+ A36FC643220BBCE9005E3C37 /* EnvironmentGeneric.cpp in Sources */, > 50DE35F5215BB01500B979C7 /* ExternalStringImpl.cpp in Sources */, > A8A473B3151A825B004123FF /* fast-dtoa.cc in Sources */, > 0F7C5FB61D885CF20044F5E2 /* FastBitVector.cpp in Sources */, >@@ -1557,7 +1571,6 @@ > 5CC0EE8A2162BC2200A1A842 /* NSURLExtras.mm in Sources */, > A8A473F4151A825B004123FF /* NumberOfCores.cpp in Sources */, > 8348BA0E21FBC0D500FD3054 /* ObjectIdentifier.cpp in Sources */, >- 5FAD3AE221B9636600BEE178 /* URLHelpers.cpp in Sources */, > A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */, > A8A473F9151A825B004123FF /* OSRandomSource.cpp in Sources */, > A8A47402151A825B004123FF /* PageBlock.cpp in Sources */, >@@ -1614,6 +1627,7 @@ > 5CC0EE7621629F1900A1A842 /* URL.cpp in Sources */, > 5C1F0595216437B30039302C /* URLCF.cpp in Sources */, > 5CC0EE892162BC2200A1A842 /* URLCocoa.mm in Sources */, >+ 5FAD3AE221B9636600BEE178 /* URLHelpers.cpp in Sources */, > 5CC0EE7521629F1900A1A842 /* URLParser.cpp in Sources */, > 1C181C8F1D307AB800F5FA16 /* UTextProvider.cpp in Sources */, > 1C181C911D307AB800F5FA16 /* UTextProviderLatin1.cpp in Sources */, >diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt >index 1f12b79f86a5a6f59c522973e9500178d3aa1740..8104da3b8d9ca4b0c118f899ef99ebddf28652a0 100644 >--- a/Source/WTF/wtf/CMakeLists.txt >+++ b/Source/WTF/wtf/CMakeLists.txt >@@ -55,6 +55,7 @@ set(WTF_PUBLIC_HEADERS > DumbPtrTraits.h > DumbValueTraits.h > EnumTraits.h >+ Environment.h > Expected.h > ExportMacros.h > FastBitVector.h >diff --git a/Source/WTF/wtf/DataLog.cpp b/Source/WTF/wtf/DataLog.cpp >index 57f9eb20d428852f7d00661dd4c50b9fef326afd..a695ab791ef06331ef7e698fb030585bf9915750 100644 >--- a/Source/WTF/wtf/DataLog.cpp >+++ b/Source/WTF/wtf/DataLog.cpp >@@ -26,14 +26,15 @@ > #include "config.h" > #include <wtf/DataLog.h> > >+#include <mutex> > #include <stdarg.h> > #include <string.h> >+#include <thread> >+#include <wtf/Environment.h> > #include <wtf/FilePrintStream.h> > #include <wtf/LockedPrintStream.h> > #include <wtf/ProcessID.h> > #include <wtf/Threading.h> >-#include <mutex> >-#include <thread> > > #if OS(UNIX) || OS(DARWIN) > #include <unistd.h> >@@ -93,7 +94,7 @@ static void initializeLogFileOnce() > #elif defined(DATA_LOG_FILENAME) > filename = DATA_LOG_FILENAME; > #else >- filename = getenv("WTF_DATA_LOG_FILENAME"); >+ filename = Environment::get("WTF_DATA_LOG_FILENAME").utf8().data(); > #endif > char actualFilename[maxPathLength + 1]; > >diff --git a/Source/WTF/wtf/Environment.h b/Source/WTF/wtf/Environment.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d16fd1bf673ea1dede7ff7d315a87a9bcc6a37bb >--- /dev/null >+++ b/Source/WTF/wtf/Environment.h >@@ -0,0 +1,40 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include <wtf/text/WTFString.h> >+ >+namespace WTF { >+namespace EnvironmentImpl { >+ >+WTF_EXPORT_PRIVATE String get(const String&); >+WTF_EXPORT_PRIVATE void set(const String& variable, const String& value); >+WTF_EXPORT_PRIVATE void add(const String& variable, const String& value); // does nothing if variable exists >+WTF_EXPORT_PRIVATE void remove(const String&); >+ >+} // namespace EnvironmentImpl >+} // namespace WTF >+ >+namespace Environment = WTF::EnvironmentImpl; >diff --git a/Source/WTF/wtf/NumberOfCores.cpp b/Source/WTF/wtf/NumberOfCores.cpp >index 62fa65a04214eb917365e86747f963c84046c223..d2153d5b9038311cedf58204825dfe48a9210440 100644 >--- a/Source/WTF/wtf/NumberOfCores.cpp >+++ b/Source/WTF/wtf/NumberOfCores.cpp >@@ -27,6 +27,7 @@ > #include <wtf/NumberOfCores.h> > > #include <cstdio> >+#include <wtf/Environment.h> > > #if OS(DARWIN) > #include <sys/param.h> >@@ -50,13 +51,16 @@ int numberOfProcessorCores() > if (s_numberOfCores > 0) > return s_numberOfCores; > >- if (const char* coresEnv = getenv("WTF_numberOfProcessorCores")) { >- unsigned numberOfCores; >- if (sscanf(coresEnv, "%u", &numberOfCores) == 1) { >+ auto coresEnv = Environment::get("WTF_numberOfProcessorCores"); >+ if (!!coresEnv) { >+ bool ok; >+ auto numberOfCores = coresEnv.toUInt(&ok); >+ if (ok) { > s_numberOfCores = numberOfCores; > return s_numberOfCores; >- } else >- fprintf(stderr, "WARNING: failed to parse WTF_numberOfProcessorCores=%s\n", coresEnv); >+ } >+ >+ fprintf(stderr, "WARNING: failed to parse WTF_numberOfProcessorCores=%s\n", coresEnv.utf8().data()); > } > > #if OS(DARWIN) >diff --git a/Source/WTF/wtf/PlatformGTK.cmake b/Source/WTF/wtf/PlatformGTK.cmake >index 297d0fa2c78f3961b0f4c3e17193fba6e5e4a3f5..c5dc7302f081668e115d5a14a8f7df83531a4572 100644 >--- a/Source/WTF/wtf/PlatformGTK.cmake >+++ b/Source/WTF/wtf/PlatformGTK.cmake >@@ -22,6 +22,7 @@ list(APPEND WTF_SOURCES > generic/MainThreadGeneric.cpp > generic/WorkQueueGeneric.cpp > >+ glib/EnvironmentGlib.cpp > glib/FileSystemGlib.cpp > glib/GLibUtilities.cpp > glib/GRefPtr.cpp >diff --git a/Source/WTF/wtf/PlatformJSCOnly.cmake b/Source/WTF/wtf/PlatformJSCOnly.cmake >index 3542fef6f90ee0a65891b3a37606545c9ac77c41..aa18e4bca36645593365e424471717deef35752d 100644 >--- a/Source/WTF/wtf/PlatformJSCOnly.cmake >+++ b/Source/WTF/wtf/PlatformJSCOnly.cmake >@@ -97,6 +97,7 @@ endif () > > if (LOWERCASE_EVENT_LOOP_TYPE STREQUAL "glib") > list(APPEND WTF_SOURCES >+ glib/EnvironmentGlib.cpp > glib/GRefPtr.cpp > glib/RunLoopGLib.cpp > ) >@@ -110,6 +111,7 @@ if (LOWERCASE_EVENT_LOOP_TYPE STREQUAL "glib") > ) > else () > list(APPEND WTF_SOURCES >+ generic/EnvironmentGeneric.cpp > generic/RunLoopGeneric.cpp > ) > endif () >diff --git a/Source/WTF/wtf/PlatformMac.cmake b/Source/WTF/wtf/PlatformMac.cmake >index 9a1f510b409f10e0232f1f1e0e2e2e59df14cb16..40095378eae9f870c707cb4e3900f16210c6a5ff 100644 >--- a/Source/WTF/wtf/PlatformMac.cmake >+++ b/Source/WTF/wtf/PlatformMac.cmake >@@ -60,6 +60,8 @@ list(APPEND WTF_SOURCES > cocoa/URLCocoa.mm > cocoa/WorkQueueCocoa.cpp > >+ generic/EnvironmentGeneric.cpp >+ > mac/DeprecatedSymbolsUsedBySafari.mm > mac/FileSystemMac.mm > mac/SchedulePairMac.mm >diff --git a/Source/WTF/wtf/PlatformPlayStation.cmake b/Source/WTF/wtf/PlatformPlayStation.cmake >index 4b6919076f391051b85e39b06f215dc9ab458681..aa45ecfc5d4883996cd76e78ef34dd1eecf6bb64 100644 >--- a/Source/WTF/wtf/PlatformPlayStation.cmake >+++ b/Source/WTF/wtf/PlatformPlayStation.cmake >@@ -1,4 +1,5 @@ > list(APPEND WTF_SOURCES >+ generic/EnvironmentGeneric.cpp > generic/MainThreadGeneric.cpp > generic/MemoryFootprintGeneric.cpp > generic/MemoryPressureHandlerGeneric.cpp >diff --git a/Source/WTF/wtf/PlatformWPE.cmake b/Source/WTF/wtf/PlatformWPE.cmake >index 38e632c3ef8b3137aa9711990e71455fbaa032cc..56a4339d456ea97ffadeb0ec36f0ea9ce5eb3f90 100644 >--- a/Source/WTF/wtf/PlatformWPE.cmake >+++ b/Source/WTF/wtf/PlatformWPE.cmake >@@ -16,6 +16,7 @@ list(APPEND WTF_SOURCES > generic/MainThreadGeneric.cpp > generic/WorkQueueGeneric.cpp > >+ glib/EnvironmentGlib.cpp > glib/FileSystemGlib.cpp > glib/GLibUtilities.cpp > glib/GRefPtr.cpp >diff --git a/Source/WTF/wtf/PlatformWin.cmake b/Source/WTF/wtf/PlatformWin.cmake >index 2c34022549d8840eb9230284a1ddd9d285239aae..d57da80a9c9347ef385bfd612152b98914d285cf 100644 >--- a/Source/WTF/wtf/PlatformWin.cmake >+++ b/Source/WTF/wtf/PlatformWin.cmake >@@ -8,6 +8,8 @@ list(APPEND WTF_PUBLIC_HEADERS > ) > > list(APPEND WTF_SOURCES >+ generic/EnvironmentGeneric.cpp >+ > text/win/TextBreakIteratorInternalICUWin.cpp > > win/CPUTimeWin.cpp >diff --git a/Source/WTF/wtf/generic/EnvironmentGeneric.cpp b/Source/WTF/wtf/generic/EnvironmentGeneric.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..c1fb777db43b336b0725f3fc734493db2c9e5a4f >--- /dev/null >+++ b/Source/WTF/wtf/generic/EnvironmentGeneric.cpp >@@ -0,0 +1,54 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include <wtf/Environment.h> >+ >+#include <stdlib.h> >+ >+namespace WTF { >+namespace EnvironmentImpl { >+ >+String get(const String& variable) >+{ >+ return getenv(variable.utf8().data()); >+} >+ >+void set(const String& variable, const String& value) >+{ >+ setenv(variable.utf8().data(), value.utf8().data(), 1); >+} >+ >+void add(const String& variable, const String& value) >+{ >+ setenv(variable.utf8().data(), value.utf8().data(), 0); >+} >+ >+void remove(const String& variable) >+{ >+ unsetenv(variable.utf8().data()); >+} >+ >+} // namespace EnvironmentImpl >+} // namespace WTF >diff --git a/Source/WTF/wtf/glib/EnvironmentGlib.cpp b/Source/WTF/wtf/glib/EnvironmentGlib.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..627c797097ae2b5a5d2f18c46fcaa7c11f69e5c9 >--- /dev/null >+++ b/Source/WTF/wtf/glib/EnvironmentGlib.cpp >@@ -0,0 +1,54 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include <wtf/Environment.h> >+ >+#include <glib.h> >+ >+namespace WTF { >+namespace EnvironmentImpl { >+ >+String get(const String& variable) >+{ >+ return g_getenv(variable.utf8().data()); >+} >+ >+void set(const String& variable, const String& value) >+{ >+ g_setenv(variable.utf8().data(), value.utf8().data(), 1); >+} >+ >+void add(const String& variable, const String& value) >+{ >+ g_setenv(variable.utf8().data(), value.utf8().data(), 0); >+} >+ >+void remove(const String& variable) >+{ >+ g_unsetenv(variable.utf8().data()); >+} >+ >+} // namespace EnvironmentImpl >+} // namespace WTF >diff --git a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >index 70d2f98e4d72c2cd15994e9fa7f7a9bc4bf0af56..717fc9c6c075ca8f6bf7862addbc426d37a06469 100644 >--- a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >+++ b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >@@ -40,6 +40,7 @@ > #include <sys/types.h> > #include <unistd.h> > #include <wtf/EnumTraits.h> >+#include <wtf/Environment.h> > #include <wtf/FileMetadata.h> > #include <wtf/text/CString.h> > #include <wtf/text/StringBuilder.h> >@@ -424,7 +425,7 @@ bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace) > String openTemporaryFile(const String& prefix, PlatformFileHandle& handle) > { > char buffer[PATH_MAX]; >- const char* tmpDir = getenv("TMPDIR"); >+ auto tmpDir = Environment::get("TMPDIR").utf8().data(); > > if (!tmpDir) > tmpDir = "/tmp";
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192405
:
361353
|
361357
|
361478
|
361490
|
361574
|
361592
|
361594
|
361595
|
361599
|
361600
|
361604
|
361613
|
361618
|
361619
|
361653
|
361736
|
361757
|
361759
|
361765
|
361774
|
361813
|
361840
|
361933
|
361937
|
361942
|
362038
|
362040
|
362041
|
362153
|
362156
|
362399