diff --git a/lib/adbc/dll_loader.ex b/lib/adbc_dll_loader_nif.ex similarity index 59% rename from lib/adbc/dll_loader.ex rename to lib/adbc_dll_loader_nif.ex index a3c7097..b4e756e 100644 --- a/lib/adbc/dll_loader.ex +++ b/lib/adbc_dll_loader_nif.ex @@ -1,7 +1,10 @@ -defmodule Adbc.Nif.DLLLoader do +defmodule Adbc.DLLLoaderNif do + # We don't use on_load callbacks because this module + # needs to be invoked from Adbc.Nif and if both have + # @on_load the order is not guaranteed in a release. @moduledoc false - @on_load :__on_load__ - def __on_load__ do + + def init do case :os.type() do {:win32, _} -> priv_dir = :code.priv_dir(:adbc) @@ -16,12 +19,6 @@ defmodule Adbc.Nif.DLLLoader do end def add_dll_directory do - case :os.type() do - {:win32, _} -> - :erlang.nif_error(:not_loaded) - - _ -> - :ok - end + :erlang.nif_error(:not_loaded) end end diff --git a/lib/adbc_nif.ex b/lib/adbc_nif.ex index 4af6551..15195ea 100644 --- a/lib/adbc_nif.ex +++ b/lib/adbc_nif.ex @@ -1,21 +1,11 @@ defmodule Adbc.Nif do @moduledoc false - alias Adbc.Nif.DLLLoader - @on_load :load_nif def load_nif do + :ok = Adbc.DLLLoaderNif.init() nif_file = ~c"#{:code.priv_dir(:adbc)}/adbc_nif" - :ok = - case :os.type() do - {:win32, _} -> - DLLLoader.add_dll_directory() - - _ -> - :ok - end - case :erlang.load_nif(nif_file, 0) do :ok -> :ok {:error, {:reload, _}} -> :ok