Bug 1508381 - remove now-unnecessary TASKCLUSTER_* variables r=tomprince
[gecko.git] / gfx / gl / GLLibraryLoader.cpp
blobaeb18d5308614495fe5fddc9ab234fbb23a3a2ac
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "GLLibraryLoader.h"
7 #include <regex>
9 #include "nsDebug.h"
11 #ifdef WIN32
12 # include <windows.h>
13 #endif
15 namespace mozilla {
16 namespace gl {
18 void ClearSymbols(const SymLoadStruct* const firstStruct) {
19 for (auto itr = firstStruct; itr->symPointer; ++itr) {
20 *itr->symPointer = nullptr;
24 bool SymbolLoader::LoadSymbols(const SymLoadStruct* const firstStruct,
25 const bool warnOnFailures) const {
26 bool ok = true;
28 for (auto itr = firstStruct; itr->symPointer; ++itr) {
29 *itr->symPointer = nullptr;
31 for (const auto& s : itr->symNames) {
32 if (!s) break;
34 const auto p = GetProcAddress(s);
35 if (p) {
36 *itr->symPointer = p;
37 break;
41 if (!*itr->symPointer) {
42 if (warnOnFailures) {
43 printf_stderr("Can't find symbol '%s'.\n", itr->symNames[0]);
45 ok = false;
49 return ok;
52 // -
54 PRFuncPtr SymbolLoader::GetProcAddress(const char* const name) const {
55 #ifdef DEBUG
56 static const std::regex kRESymbol("[a-z].*");
57 if (!std::regex_match(name, kRESymbol)) {
58 gfxCriticalError() << "Bad symbol name : " << name;
60 #endif
62 PRFuncPtr ret = nullptr;
63 if (!ret && mLib) {
64 ret = PR_FindFunctionSymbol(mLib, name);
66 if (!ret && mPfn) {
67 ret = mPfn(name);
69 return ret;
72 } // namespace gl
73 } // namespace mozilla