[aseprite] 256/308: Add functions to load dynamic libraries from base-lib

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:45:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit d2f1e2b6d200360bfc1e33db5373606b2a27233d
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Feb 24 13:11:40 2016 -0300

    Add functions to load dynamic libraries from base-lib
---
 src/base/CMakeLists.txt |  5 ++++-
 src/base/dll.cpp        | 17 +++++++++++++++++
 src/base/dll.h          | 29 +++++++++++++++++++++++++++++
 src/base/dll_unix.h     | 27 +++++++++++++++++++++++++++
 src/base/dll_win32.h    | 29 +++++++++++++++++++++++++++++
 5 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
index ca43bb7..77c1424 100644
--- a/src/base/CMakeLists.txt
+++ b/src/base/CMakeLists.txt
@@ -1,5 +1,5 @@
 # Aseprite Base Library
-# Copyright (c) 2001-2015 David Capello
+# Copyright (c) 2001-2016 David Capello
 
 include(CheckCSourceCompiles)
 include(CheckCXXSourceCompiles)
@@ -48,6 +48,7 @@ set(BASE_SOURCES
   connection.cpp
   convert_to.cpp
   debug.cpp
+  dll.cpp
   errno_string.cpp
   exception.cpp
   file_handle.cpp
@@ -83,4 +84,6 @@ target_link_libraries(base-lib modp_b64)
 
 if(WIN32)
   target_link_libraries(base-lib dbghelp shlwapi)
+else()
+  target_link_libraries(base-lib dl)
 endif()
diff --git a/src/base/dll.cpp b/src/base/dll.cpp
new file mode 100644
index 0000000..e4b52d3
--- /dev/null
+++ b/src/base/dll.cpp
@@ -0,0 +1,17 @@
+// Aseprite Base Library
+// Copyright (c) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "base/dll.h"
+
+#ifdef _WIN32
+  #include "base/dll_win32.h"
+#else
+  #include "base/dll_unix.h"
+#endif
diff --git a/src/base/dll.h b/src/base/dll.h
new file mode 100644
index 0000000..e699758
--- /dev/null
+++ b/src/base/dll.h
@@ -0,0 +1,29 @@
+// Aseprite Base Library
+// Copyright (c) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef BASE_DLL_H_INCLUDED
+#define BASE_DLL_H_INCLUDED
+#pragma once
+
+#include <string>
+
+namespace base {
+
+typedef void* dll;
+typedef void* dll_proc;
+
+dll load_dll(const std::string& filename);
+void unload_dll(dll lib);
+dll_proc get_dll_proc_base(dll lib, const char* procName);
+
+template<typename T>
+inline T get_dll_proc(dll lib, const char* procName) {
+  return reinterpret_cast<T>(get_dll_proc_base(lib, procName));
+}
+
+} // namespace base
+
+#endif
diff --git a/src/base/dll_unix.h b/src/base/dll_unix.h
new file mode 100644
index 0000000..127b283
--- /dev/null
+++ b/src/base/dll_unix.h
@@ -0,0 +1,27 @@
+// Aseprite Base Library
+// Copyright (c) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#include "base/string.h"
+#include <dlfcn.h>
+
+namespace base {
+
+dll load_dll(const std::string& filename)
+{
+  return dlopen(filename.c_str(), RTLD_LAZY | RTLD_GLOBAL);
+}
+
+void unload_dll(dll lib)
+{
+  dlclose(lib);
+}
+
+dll_proc get_dll_proc_base(dll lib, const char* procName)
+{
+  return dlsym(lib, procName);
+}
+
+} // namespace base
diff --git a/src/base/dll_win32.h b/src/base/dll_win32.h
new file mode 100644
index 0000000..5378321
--- /dev/null
+++ b/src/base/dll_win32.h
@@ -0,0 +1,29 @@
+// Aseprite Base Library
+// Copyright (c) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#include "base/string.h"
+#include <windows.h>
+
+namespace base {
+
+dll load_dll(const std::string& filename)
+{
+  return LoadLibrary(base::from_utf8(filename).c_str());
+}
+
+void unload_dll(dll lib)
+{
+  FreeLibrary((HMODULE)lib);
+}
+
+dll_proc get_dll_proc_base(dll lib, const char* procName)
+{
+  return reinterpret_cast<dll_proc>(
+    GetProcAddress((HMODULE)lib, procName));
+}
+
+
+} // namespace base

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list