gmodule.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* GMODULE - GLIB wrapper code for dynamic module loading
  2. * Copyright (C) 1998 Tim Janik
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. #ifndef __GMODULE_H__
  26. #define __GMODULE_H__
  27. #include <glib.h>
  28. #include <gmodule/gmodule-visibility.h>
  29. G_BEGIN_DECLS
  30. /* exporting and importing functions, this is special cased
  31. * to feature Windows dll stubs.
  32. */
  33. #if defined(_WIN32) || defined(__CYGWIN__)
  34. # define G_MODULE_EXPORT __declspec(dllexport)
  35. # define G_MODULE_IMPORT __declspec(dllimport) extern
  36. #elif __GNUC__ >= 4
  37. # define G_MODULE_EXPORT __attribute__((visibility("default")))
  38. # define G_MODULE_IMPORT extern
  39. #else /* !defined(_WIN32) && !defined(__CYGWIN__) && __GNUC__ < 4 */
  40. # define G_MODULE_EXPORT
  41. # define G_MODULE_IMPORT extern
  42. #endif
  43. /**
  44. * GModuleFlags:
  45. * @G_MODULE_BIND_LAZY: specifies that symbols are only resolved when
  46. * needed. The default action is to bind all symbols when the module
  47. * is loaded.
  48. * @G_MODULE_BIND_LOCAL: specifies that symbols in the module should
  49. * not be added to the global name space. The default action on most
  50. * platforms is to place symbols in the module in the global name space,
  51. * which may cause conflicts with existing symbols.
  52. * @G_MODULE_BIND_MASK: mask for all flags.
  53. *
  54. * Flags passed to g_module_open().
  55. * Note that these flags are not supported on all platforms.
  56. */
  57. typedef enum
  58. {
  59. G_MODULE_BIND_LAZY = 1 << 0,
  60. G_MODULE_BIND_LOCAL = 1 << 1,
  61. G_MODULE_BIND_MASK = 0x03
  62. } GModuleFlags;
  63. typedef struct _GModule GModule;
  64. typedef const gchar* (*GModuleCheckInit) (GModule *module);
  65. typedef void (*GModuleUnload) (GModule *module);
  66. #define G_MODULE_ERROR g_module_error_quark () GMODULE_AVAILABLE_MACRO_IN_2_70
  67. GMODULE_AVAILABLE_IN_2_70
  68. GQuark g_module_error_quark (void);
  69. /**
  70. * GModuleError:
  71. * @G_MODULE_ERROR_FAILED: there was an error loading or opening a module file
  72. * @G_MODULE_ERROR_CHECK_FAILED: a module returned an error from its `g_module_check_init()` function
  73. *
  74. * Errors returned by g_module_open_full().
  75. *
  76. * Since: 2.70
  77. */
  78. typedef enum
  79. {
  80. G_MODULE_ERROR_FAILED,
  81. G_MODULE_ERROR_CHECK_FAILED,
  82. } GModuleError
  83. GMODULE_AVAILABLE_ENUMERATOR_IN_2_70;
  84. /* return TRUE if dynamic module loading is supported */
  85. GMODULE_AVAILABLE_IN_ALL
  86. gboolean g_module_supported (void) G_GNUC_CONST;
  87. /* open a module 'file_name' and return handle, which is NULL on error */
  88. GMODULE_AVAILABLE_IN_ALL
  89. GModule* g_module_open (const gchar *file_name,
  90. GModuleFlags flags);
  91. GMODULE_AVAILABLE_IN_2_70
  92. GModule *g_module_open_full (const gchar *file_name,
  93. GModuleFlags flags,
  94. GError **error);
  95. /* close a previously opened module, returns TRUE on success */
  96. GMODULE_AVAILABLE_IN_ALL
  97. gboolean g_module_close (GModule *module);
  98. /* make a module resident so g_module_close on it will be ignored */
  99. GMODULE_AVAILABLE_IN_ALL
  100. void g_module_make_resident (GModule *module);
  101. /* query the last module error as a string */
  102. GMODULE_AVAILABLE_IN_ALL
  103. const gchar * g_module_error (void);
  104. /* retrieve a symbol pointer from 'module', returns TRUE on success */
  105. GMODULE_AVAILABLE_IN_ALL
  106. gboolean g_module_symbol (GModule *module,
  107. const gchar *symbol_name,
  108. gpointer *symbol);
  109. /* retrieve the file name from an existing module */
  110. GMODULE_AVAILABLE_IN_ALL
  111. const gchar * g_module_name (GModule *module);
  112. /* Build the actual file name containing a module. 'directory' is the
  113. * directory where the module file is supposed to be, or NULL or empty
  114. * in which case it should either be in the current directory or, on
  115. * some operating systems, in some standard place, for instance on the
  116. * PATH. Hence, to be absolutely sure to get the correct module,
  117. * always pass in a directory. The file name consists of the directory,
  118. * if supplied, and 'module_name' suitably decorated according to
  119. * the operating system's conventions (for instance lib*.so or *.dll).
  120. *
  121. * No checks are made that the file exists, or is of correct type.
  122. */
  123. GMODULE_DEPRECATED_IN_2_76
  124. gchar* g_module_build_path (const gchar *directory,
  125. const gchar *module_name);
  126. G_END_DECLS
  127. #endif /* __GMODULE_H__ */