Skip to content

Commit

Permalink
Fix struct procedure constructor
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Oct 7, 2023
1 parent 80d4703 commit d0132c8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.28_amd64.deb
sudo apt install build/meevax_0.5.29_amd64.deb
```

or
Expand Down Expand Up @@ -131,9 +131,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.28.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.29.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.28_amd64.deb`
| `package` | Generate debian package `meevax_0.5.29_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.28
0.5.29
2 changes: 1 addition & 1 deletion example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace meevax; // NOTE: DIRTY HACK

extern "C"
{
auto length_of_arguments(object const& xs)
auto arity(object const& xs)
{
return make<exact_integer>(length(xs));
}
Expand Down
8 changes: 4 additions & 4 deletions example/example.ss
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

; ------------------------------------------------------------------------------

(define length-of-arguments
(procedure "build/libexample.so" 'length_of_arguments))
(define arity
(procedure "build/libexample.so" 'arity))

(check (procedure? length-of-arguments) => #t)
(check (procedure? arity) => #t)

(check (length-of-arguments 'hoge 42 #(1 2 3) 3.14) => 4)
(check (arity 'hoge 42 #(1 2 3) 3.14) => 4)

; ------------------------------------------------------------------------------

Expand Down
21 changes: 10 additions & 11 deletions src/kernel/procedure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ inline namespace kernel
return os << magenta("#,(") << green("procedure") << " " << symbol(datum.name) << magenta(")");
}

auto dlopen(std::string const& libfoo_so) -> void *
auto dlopen(std::string const& filename) -> void *
{
auto dlclose = [](void * const handle)
{
Expand All @@ -52,18 +52,17 @@ inline namespace kernel

try
{
return dynamic_libraries.at(libfoo_so).get();
return dynamic_libraries.at(filename).get();
}
catch (std::out_of_range const&)
{
if (auto handle = ::dlopen(libfoo_so.c_str(), RTLD_LAZY | RTLD_GLOBAL); handle)
if (auto handle = ::dlopen(filename.c_str(), RTLD_LAZY | RTLD_GLOBAL); handle)
{
dynamic_libraries.emplace(
std::piecewise_construct,
std::forward_as_tuple(libfoo_so),
std::forward_as_tuple(handle, dlclose));
dynamic_libraries.emplace(std::piecewise_construct,
std::forward_as_tuple(filename),
std::forward_as_tuple(handle, dlclose));

return dlopen(libfoo_so);
return dlopen(filename);
}
else
{
Expand All @@ -72,9 +71,9 @@ inline namespace kernel
}
}

auto dlsym(std::string const& name, void * const handle) -> FUNCTION((*))
auto dlsym(std::string const& symbol, void * const handle) -> FUNCTION((*))
{
if (auto address = ::dlsym(handle, name.c_str()); address)
if (auto address = ::dlsym(handle, symbol.c_str()); address)
{
return reinterpret_cast<FUNCTION((*))>(address);
}
Expand All @@ -85,7 +84,7 @@ inline namespace kernel
}

procedure::procedure(std::string const& filename, std::string const& symbol)
: procedure { name, dlsym(symbol, dlopen(filename)) }
: procedure { filename, dlsym(symbol, dlopen(filename)) }
{}
} // namespace kernel
} // namespace meevax

0 comments on commit d0132c8

Please sign in to comment.