Class Module

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Module extends ProxyInstance

The GModule struct is an opaque data structure to represent a dynamically-loaded module. It should only be accessed via the following functions.

To ensure correct lock ordering, these functions must not be called from global constructors (for example, those using GCC’s __attribute__((constructor)) attribute).

  • Constructor Details

    • Module

      public Module(MemorySegment address)
      Create a Module proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • buildPath

      @Deprecated public static String buildPath(@Nullable String directory, String moduleName)
      Deprecated.
      Use g_module_open() instead with moduleName as the basename of the file_name argument. See G_MODULE_SUFFIX for why.

      A portable way to build the filename of a module. The platform-specific prefix and suffix are added to the filename, if needed, and the result is added to the directory, using the correct separator character.

      The directory should specify the directory where the module can be found. It can be null or an empty string to indicate that the module is in a standard platform-specific directory, though this is not recommended since the wrong module may be found.

      For example, calling g_module_build_path() on a Linux system with a directory of /lib and a moduleName of "mylibrary" will return /lib/libmylibrary.so. On a Windows system, using \\Windows as the directory it will return \\Windows\\mylibrary.dll.

      Parameters:
      directory - the directory where the module is. This can be null or the empty string to indicate that the standard platform-specific directories will be used, though that is not recommended
      moduleName - the name of the module
      Returns:
      the complete path of the module, including the standard library prefix and suffix. This should be freed when no longer needed
    • error

      public static String error()
      Gets a string describing the last module error.
      Returns:
      a string describing the last module error
    • errorQuark

      public static Quark errorQuark()
    • open

      public static Module open(@Nullable String fileName, Set<ModuleFlags> flags)
      A thin wrapper function around g_module_open_full()
      Parameters:
      fileName - the name or path to the file containing the module, or null to obtain a GModule representing the main program itself
      flags - the flags used for opening the module. This can be the logical OR of any of the GModuleFlags.
      Returns:
      a GModule on success, or null on failure
    • open

      public static Module open(@Nullable String fileName, ModuleFlags... flags)
      A thin wrapper function around g_module_open_full()
      Parameters:
      fileName - the name or path to the file containing the module, or null to obtain a GModule representing the main program itself
      flags - the flags used for opening the module. This can be the logical OR of any of the GModuleFlags.
      Returns:
      a GModule on success, or null on failure
    • openFull

      public static Module openFull(@Nullable String fileName, Set<ModuleFlags> flags) throws GErrorException

      Opens a module. If the module has already been opened, its reference count is incremented. If not, the module is searched using fileName.

      Since 2.76, the search order/behavior is as follows:

      1. If fileName exists as a regular file, it is used as-is; else
      2. If fileName doesn't have the correct suffix and/or prefix for the platform, then possible suffixes and prefixes will be added to the basename till a file is found and whatever is found will be used; else
      3. If fileName doesn't have the ".la"-suffix, ".la" is appended. Either way, if a matching .la file exists (and is a libtool archive) the libtool archive is parsed to find the actual file name, and that is used.

      If, at the end of all this, we have a file path that we can access on disk, it is opened as a module. If not, fileName is attempted to be opened as a module verbatim in the hopes that the system implementation will somehow be able to access it. If that is not possible, null is returned.

      Note that this behaviour was different prior to 2.76, but there is some overlap in functionality. If backwards compatibility is an issue, kindly consult earlier GModule documentation for the prior search order/behavior of fileName.

      Parameters:
      fileName - the name or path to the file containing the module, or null to obtain a GModule representing the main program itself
      flags - the flags used for opening the module. This can be the logical OR of any of the GModuleFlags
      Returns:
      a GModule on success, or null on failure
      Throws:
      GErrorException - see GError
      Since:
      2.70
    • openFull

      public static Module openFull(@Nullable String fileName, ModuleFlags... flags) throws GErrorException

      Opens a module. If the module has already been opened, its reference count is incremented. If not, the module is searched using fileName.

      Since 2.76, the search order/behavior is as follows:

      1. If fileName exists as a regular file, it is used as-is; else
      2. If fileName doesn't have the correct suffix and/or prefix for the platform, then possible suffixes and prefixes will be added to the basename till a file is found and whatever is found will be used; else
      3. If fileName doesn't have the ".la"-suffix, ".la" is appended. Either way, if a matching .la file exists (and is a libtool archive) the libtool archive is parsed to find the actual file name, and that is used.

      If, at the end of all this, we have a file path that we can access on disk, it is opened as a module. If not, fileName is attempted to be opened as a module verbatim in the hopes that the system implementation will somehow be able to access it. If that is not possible, null is returned.

      Note that this behaviour was different prior to 2.76, but there is some overlap in functionality. If backwards compatibility is an issue, kindly consult earlier GModule documentation for the prior search order/behavior of fileName.

      Parameters:
      fileName - the name or path to the file containing the module, or null to obtain a GModule representing the main program itself
      flags - the flags used for opening the module. This can be the logical OR of any of the GModuleFlags
      Returns:
      a GModule on success, or null on failure
      Throws:
      GErrorException - see GError
      Since:
      2.70
    • supported

      public static boolean supported()
      Checks if modules are supported on the current platform.
      Returns:
      true if modules are supported
    • close

      public boolean close()
      Closes a module.
      Returns:
      true on success
    • makeResident

      public void makeResident()
      Ensures that a module will never be unloaded. Any future g_module_close() calls on the module will be ignored.
    • name

      public String name()

      Returns the filename that the module was opened with.

      If this Module refers to the application itself, "main" is returned.

      Returns:
      the filename of the module
    • symbol

      public boolean symbol(String symbolName, @Nullable Out<MemorySegment> symbol)
      Gets a symbol pointer from a module, such as one exported by G_MODULE_EXPORT. Note that a valid symbol can be null.
      Parameters:
      symbolName - the name of the symbol to find
      symbol - returns the pointer to the symbol value
      Returns:
      true on success