Skip to content

Commit

Permalink
Crate renamed to dlopen
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonwieloch committed Sep 4, 2017
1 parent 434b41f commit d10a06f
Show file tree
Hide file tree
Showing 31 changed files with 116 additions and 116 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "dynlib"
name = "dlopen"
version = "0.1.0"
authors = ["Szymon Wieloch <szymon.wieloch@gmail.com>"]
description = "A library for opening and operating on dynamically loadable libraries."
keywords = [
#common functions
"dlopen", "dll", "so", "dylib", "shared"]
license = "MIT"
repository = "https://github.com/szymonwieloch/rust-dynlib"
repository = "https://github.com/szymonwieloch/rust-dlopen"

[dependencies.dynlib_derive]
path = "rust-dynlib-derive"
[dependencies.dlopen_derive]
path = "rust-dlopen-derive"
version = "0.1.0"

[target.'cfg(windows)'.dependencies]
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# rust-dynlib
# rust-dlopen

[![Travis CI][tcii]][tci] [![Appveyor CI][acii]][aci]

[tcii]: https://travis-ci.org/szymonwieloch/rust-dynlib.svg?branch=master
[tci]: https://travis-ci.org/szymonwieloch/rust-dynlib
[acii]: https://ci.appveyor.com/api/projects/status/github/szymonwieloch/rust-dynlib?svg=true
[aci]: https://ci.appveyor.com/project/szymonwieloch/rust-dynlib
[tcii]: https://travis-ci.org/szymonwieloch/rust-dlopen.svg?branch=master
[tci]: https://travis-ci.org/szymonwieloch/rust-dlopen
[acii]: https://ci.appveyor.com/api/projects/status/github/szymonwieloch/rust-dlopen?svg=true
[aci]: https://ci.appveyor.com/project/szymonwieloch/rust-dlopen

A long time ago in a dirty basement far, far away a programmer was trying to dynamically load a library using standard C API (because he didnt know Rust yet):

Expand Down Expand Up @@ -63,7 +63,7 @@ loading libraries requires transmutation of obtained pointers).
Cargo.toml:
```toml
[dependencies]
dynlib = "0.1"
dlopen = "0.1"
```
# License
This code is licensed under [MIT](./LICENSE) license.
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#rust-dynlib examples
#rust-dlopen examples

Files in directory perform very similar operations
but they use different APIs. You can compare these
Expand All @@ -20,6 +20,6 @@ library gets unloaded. Please notice that this
bug is related to building dynamic link libraries
(in this case the example library), not to loading
libraries.
If you userust-dynlib for working with correctly built
If you userust-dlopen for working with correctly built
dynamic link libraries, everything should work
normally.
4 changes: 2 additions & 2 deletions examples/commons/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate libc;
extern crate dynlib;
extern crate dlopen;
extern crate regex;
use dynlib::utils::{PLATFORM_FILE_EXTENSION, PLATFORM_FILE_PREFIX};
use dlopen::utils::{PLATFORM_FILE_EXTENSION, PLATFORM_FILE_PREFIX};
use std::env;
use std::path::{PathBuf};
use libc::{c_int};
Expand Down
4 changes: 2 additions & 2 deletions examples/raw.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate dynlib;
extern crate dlopen;
extern crate libc;
#[macro_use]
extern crate const_cstr;

mod commons;

use commons::{SomeData, example_lib_path};
use dynlib::raw::{Library};
use dlopen::raw::{Library};
use libc::{c_int, c_char};
use std::ffi::CStr;

Expand Down
6 changes: 3 additions & 3 deletions examples/symbor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate dynlib;
extern crate dlopen;
extern crate libc;
#[macro_use]
extern crate const_cstr;

mod commons;

use commons::{SomeData, example_lib_path};
use dynlib::symbor::{Library};
use dynlib::utils::platform_file_name;
use dlopen::symbor::{Library};
use dlopen::utils::platform_file_name;
use libc::{c_char, c_int};
use std::ffi::CStr;

Expand Down
8 changes: 4 additions & 4 deletions examples/symbor_api.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#[macro_use]
extern crate dynlib_derive;
extern crate dlopen_derive;
#[macro_use]
extern crate dynlib;
extern crate dlopen;
extern crate libc;
#[macro_use]
extern crate const_cstr;

mod commons;
use commons::{SomeData, example_lib_path};
use dynlib::symbor::{Library, PtrOrNull, PtrOrNullMut, Ref, RefMut, Symbol, SymBorApi};
use dlopen::symbor::{Library, PtrOrNull, PtrOrNullMut, Ref, RefMut, Symbol, SymBorApi};
use libc::{c_char, c_int};
use std::ffi::CStr;

Expand All @@ -21,7 +21,7 @@ struct Api<'a> {
pub c_fun_add_two: Symbol<'a, unsafe extern "C" fn(c_int) -> c_int>,
pub rust_i32: Ref<'a, i32>,
pub rust_i32_mut: RefMut<'a, i32>,
#[dynlib_name="rust_i32_mut"]
#[dlopen_name="rust_i32_mut"]
pub rust_i32_ptr: Symbol<'a, * const i32>,
pub c_int: Ref<'a, c_int>,
pub c_struct: Ref<'a, SomeData>,
Expand Down
8 changes: 4 additions & 4 deletions examples/wrapper_api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate dynlib;
extern crate dlopen;
#[macro_use]
extern crate dynlib_derive;
extern crate dlopen_derive;
extern crate libc;
#[macro_use]
extern crate const_cstr;
use dynlib::wrapper::{Container, WrapperApi};
use dlopen::wrapper::{Container, WrapperApi};
use libc::{c_int, c_char};
use std::ffi::CStr;

Expand All @@ -20,7 +20,7 @@ struct Api<'a> {
c_fun_add_two: unsafe extern "C" fn(arg: c_int) -> c_int,
rust_i32: &'a i32,
rust_i32_mut: &'a mut i32,
#[dynlib_name="rust_i32_mut"]
#[dlopen_name="rust_i32_mut"]
rust_i32_ptr: * const i32,
c_int: &'a c_int,
c_struct: &'a SomeData,
Expand Down
8 changes: 4 additions & 4 deletions examples/wrapper_multi_api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[macro_use]
extern crate dynlib_derive;
extern crate dynlib;
extern crate dlopen_derive;
extern crate dlopen;
extern crate libc;
mod commons;
use commons::{example_lib_path, SomeData};
use libc::{c_double, c_char, c_int};
use dynlib::wrapper::{Container, WrapperApi, WrapperMultiApi};
use dynlib::utils::platform_file_name;
use dlopen::wrapper::{Container, WrapperApi, WrapperMultiApi};
use dlopen::utils::platform_file_name;
use std::ffi::CStr;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "dynlib_derive"
name = "dlopen_derive"
version = "0.1.0"
authors = ["Szymon Wieloch <szymon.wieloch@gmail.com>"]
description = "Derive macros for the dynlib crate."
description = "Derive macros for the dlopen crate."
license = "MIT"

[lib]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn impl_library_api(ast: &DeriveInput) -> quote::Tokens {
let tok_iter = fields.iter().map(field_to_tokens);
let q = quote! {
impl<'a> SymBorApi<'a> for #name<'a> {
unsafe fn load(lib: &'a ::dynlib::symbor::Library) -> Result<#name<'a>,::dynlib::Error> {
unsafe fn load(lib: &'a ::dlopen::symbor::Library) -> Result<#name<'a>,::dlopen::Error> {
Ok(#name {
#(#tok_iter),*
})
Expand All @@ -33,7 +33,7 @@ fn field_to_tokens(field: &Field) -> quote::Tokens {
let raw_result = lib.ptr_or_null_cstr::<()>(
::std::ffi::CStr::from_bytes_with_nul_unchecked(concat!(#symbol_name, "\0").as_bytes())
);
dynlib::symbor::FromRawResult::from_raw_result(raw_result)?
dlopen::symbor::FromRawResult::from_raw_result(raw_result)?
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use syn::{Field, DeriveInput, Body, VariantData, Lit, MetaItem};

pub fn symbol_name(field: &Field) -> &str {
match find_str_attr_val(field, "dynlib_name") {
match find_str_attr_val(field, "dlopen_name") {
Some(val) => val,
None => //not found, so use field name
match field.ident {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use api::impl_library_api;
use wrapper::impl_wrapper_api;
use multi_api::impl_wrapper_multi_api;

#[proc_macro_derive(WrapperApi, attributes(dynlib_name, dynlib_allow_null))]
#[proc_macro_derive(WrapperApi, attributes(dlopen_name, dlopen_allow_null))]
pub fn wrapper_api(input: TokenStream) -> TokenStream {
// Construct a string representation of the type definition
let s = input.to_string();
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn wrapper_multi_api(input: TokenStream) -> TokenStream {
gen.parse().unwrap()
}

#[proc_macro_derive(SymBorApi, attributes(dynlib_name))]
#[proc_macro_derive(SymBorApi, attributes(dlopen_name))]
pub fn library_api(input: TokenStream) -> TokenStream {
// Construct a string representation of the type definition
let s = input.to_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn impl_wrapper_multi_api(ast: &DeriveInput) -> quote::Tokens {
let q = quote! {
impl #generics WrapperMultiApi for #name #generics{}

impl #generics ::dynlib::wrapper::WrapperApi for # name #generics{
unsafe fn load(lib: & ::dynlib::raw::Library) -> Result<Self,::dynlib::Error> {
impl #generics ::dlopen::wrapper::WrapperApi for # name #generics{
unsafe fn load(lib: & ::dlopen::raw::Library) -> Result<Self,::dlopen::Error> {
Ok(#name {
#(#tok_iter),*
})
Expand All @@ -34,7 +34,7 @@ fn field_to_tokens(field: &Field) -> quote::Tokens {
//panic!("type_name = {}, {:?}", field_type_name, field);

quote! {
#field_name: ::dynlib::wrapper::WrapperApi::load(&lib)?
#field_name: ::dlopen::wrapper::WrapperApi::load(&lib)?
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use syn::{Field, Ty, DeriveInput, Visibility, BareFnArg, FunctionRetTy, MutTy, M
use quote;
use super::common::{get_fields, symbol_name, has_marker_attr};

const ALLOW_NULL: &str = "dynlib_allow_null";
const ALLOW_NULL: &str = "dlopen_allow_null";
const TRAIT_NAME: &str = "WrapperApi";

pub fn impl_wrapper_api(ast: &DeriveInput) -> quote::Tokens {
Expand All @@ -24,7 +24,7 @@ pub fn impl_wrapper_api(ast: &DeriveInput) -> quote::Tokens {
let wrapper_iter = fields.iter().filter_map(field_to_wrapper);
let q = quote! {
impl #generics WrapperApi for #struct_name #generics {
unsafe fn load(lib: & ::dynlib::raw::Library ) -> Result<Self, ::dynlib::Error> {
unsafe fn load(lib: & ::dlopen::raw::Library ) -> Result<Self, ::dlopen::Error> {
Ok(Self{
#(#field_iter),*
})
Expand Down Expand Up @@ -83,7 +83,7 @@ fn allow_null_field(field: &Field, ptr: &Box<MutTy>) -> quote::Tokens {
) {
Ok(val) => val,
Err(err) => match err {
::dynlib::Error::NullSymbol => ::std::ptr:: #null_fun (),
::dlopen::Error::NullSymbol => ::std::ptr:: #null_fun (),
_ => return Err(err)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/raw/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl Library {
#Example
```no_run
extern crate dynlib;
use dynlib::raw::Library;
extern crate dlopen;
use dlopen::raw::Library;
fn main() {
//use full path
Expand Down Expand Up @@ -76,9 +76,9 @@ impl Library {
#Example
```no_run
extern crate dynlib;
use dynlib::raw::Library;
use dynlib::Error;
extern crate dlopen;
use dlopen::raw::Library;
use dlopen::Error;
use std::ptr::null;
fn main(){
let lib = Library::open("libyourlib.so").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ approach to loading dynamic link libraries.
# Example
```no_run
extern crate dynlib;
use dynlib::raw::Library;
extern crate dlopen;
use dlopen::raw::Library;
fn main(){
let lib = Library::open("libexample.so").unwrap();
let fun_add_one: unsafe extern "C" fn(i32)->i32 = unsafe{lib.symbol("add_one")}.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/symbor/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ generated `load(&Library)` function to load all symbols from previously opened l
```no_run
#[macro_use]
extern crate dynlib_derive;
extern crate dynlib;
extern crate dlopen_derive;
extern crate dlopen;
extern crate libc;
use dynlib::symbor::{Library, Symbol, SymBorApi, PtrOrNull, RefMut, PtrOrNullMut};
use dlopen::symbor::{Library, Symbol, SymBorApi, PtrOrNull, RefMut, PtrOrNullMut};
use libc::{c_double, c_char};
#[derive(SymBorApi)]
Expand All @@ -23,7 +23,7 @@ struct Example<'a> {
pub optional_fun: Option<Symbol<'a, unsafe extern "C" fn()>>,
pub nullable_ptr: PtrOrNullMut<'a, c_char>,
pub mut_ref_i32: Symbol<'a, &'a mut i32>,
#[dynlib_name="mut_ref_i32"]
#[dlopen_name="mut_ref_i32"]
pub the_same_mut_ref_i32: RefMut<'a, i32>,
pub not_nullable_ptr: Symbol<'a, * mut c_double>
}
Expand Down Expand Up @@ -51,7 +51,7 @@ fn main(){
Please notice several supported features:
* By default `SymBorApi` uses the field name to obtain a symbol from the library.
You can override the symbol name using the `dynlib_name` attribute.
You can override the symbol name using the `dlopen_name` attribute.
* All kind of objects from the `symbor` module implement the Deref or DerefMut trait.
This means that you can use them as if you would use primitive types that they wrap.
* You can obtain optional symbols. This is very useful when you are dealing with
Expand Down
6 changes: 3 additions & 3 deletions src/symbor/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ This structure allows you to do it.
```no_run
#[macro_use]
extern crate dynlib_derive;
extern crate dynlib;
use dynlib::symbor::{Library, Symbol, Ref, PtrOrNull, SymBorApi, Container};
extern crate dlopen_derive;
extern crate dlopen;
use dlopen::symbor::{Library, Symbol, Ref, PtrOrNull, SymBorApi, Container};
#[derive(SymBorApi)]
struct ExampleApi<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/symbor/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ dangling symbols is prevented.
#Example
```no_run
extern crate dynlib;
use dynlib::symbor::Library;
extern crate dlopen;
use dlopen::symbor::Library;
fn main(){
let lib = Library::open("libexample.dylib").unwrap();
Expand Down
Loading

0 comments on commit d10a06f

Please sign in to comment.