Skip to content

Commit

Permalink
Load NIFs explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 27, 2025
1 parent c3b3bd4 commit 2e2c15a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
17 changes: 7 additions & 10 deletions lib/adbc/dll_loader.ex → lib/adbc_dll_loader_nif.ex
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
12 changes: 1 addition & 11 deletions lib/adbc_nif.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2e2c15a

Please sign in to comment.