Skip to content

Commit

Permalink
Time for new things
Browse files Browse the repository at this point in the history
  • Loading branch information
bbqsrc committed Mar 2, 2024
1 parent 85cec53 commit ee4a9f5
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 339 deletions.
523 changes: 220 additions & 303 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "cffi"
description = "Safe* C FFI interface generation"
version = "0.1.7"
version = "0.2.0-dev"
authors = [
"Brendan Molloy <[email protected]>",
"Pascal Hertleif <[email protected]>"
]
edition = "2018"
edition = "2021"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/cffi-rs/cffi"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cffi-impl = { version = "=0.1.6", path = "./impl" }
cffi-impl = { version = "=0.2.0-dev", path = "./impl" }
libc = "0.2.79"
log = "0.4.11"
url = { version = "2.1.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019-2020 Brendan Molloy <[email protected]>
Copyright (c) 2019-2024 Brendan Molloy <[email protected]>
Copyright (c) 2019 Pascal Hertleif

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
20 changes: 10 additions & 10 deletions impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
[package]
name = "cffi-impl"
description = "Safe* C FFI interface generator - macro"
version = "0.1.6"
version = "0.2.0-dev"
authors = [
"Brendan Molloy <[email protected]>",
"Pascal Hertleif <[email protected]>"
]
edition = "2018"
edition = "2021"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/cffi-rs/cffi"

[lib]
proc-macro = true

[dependencies]
syn = "1.0.44"
syn = "2.0.52"
quote = "1.0.7"
proc-macro2 = "1.0.24"
darling = "0.10.2"
heck = "0.3"
ctor = "0.1.16"
darling = "0.20.8"
heck = "0.4.1"
ctor = "0.2.7"
log = "0.4.11"
pretty_env_logger = "0.4.0"
phf = "0.7.24"
pretty_env_logger = "0.5.0"
phf = "0.11.2"

[dev-dependencies]
assert_tokens_eq = { git = "https://github.com/killercup/assert_tokens_eq" }

[build-dependencies]
phf_codegen = "0.7.24"
syn = { version = "1.0.5", features = ["full", "extra-traits"] }
phf_codegen = "0.11.2"
syn = { version = "2.0.52", features = ["full", "extra-traits"] }
quote = "1.0.2"
proc-macro2 = "1.0.4"
2 changes: 1 addition & 1 deletion impl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() {
&format!("\"{}\"", quote! { #value }.to_string()),
);
}
map.build(&mut file).unwrap();
write!(&mut file, "{}", map.build()).unwrap();
write!(&mut file, ";\n").unwrap();

let types: Vec<Type> = type_array![
Expand Down
15 changes: 5 additions & 10 deletions impl/src/attr/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,13 @@ impl MarshalAttr {
}

pub fn from_attribute(attr: syn::Attribute) -> Result<Option<MarshalAttr>, syn::Error> {
match attr.path.segments.first() {
Some(v) => {
if v.ident.to_string() != "marshal" {
return Ok(None);
}
}
None => {
return Ok(None);
}
if !attr.meta.path().is_ident("marshal") {
return Ok(None);
}

let marshal_ty: syn::Type = match syn::parse2(attr.tokens) {
let list = attr.meta.require_list()?;

let marshal_ty: syn::Type = match syn::parse2(list.tokens.clone()) {
Ok(v) => v,
Err(e) => return Err(e),
};
Expand Down
8 changes: 6 additions & 2 deletions impl/src/call_fn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use log::debug;
use proc_macro2::TokenStream;
use quote::quote;
use syn::token::Paren;

use super::{function::Function, function::InnerFn, return_type::ReturnType};
use crate::attr::marshal::MarshalAttr;
Expand Down Expand Up @@ -30,8 +31,11 @@ pub fn call_with_function(
pound_token: <syn::Token![#]>::default(),
style: syn::AttrStyle::Outer,
bracket_token: syn::token::Bracket::default(),
path: syn::parse2(quote! { inline }).unwrap(),
tokens: quote! { (always) },
meta: syn::Meta::List(syn::MetaList {
path: syn::parse2(quote! { inline }).unwrap(),
delimiter: syn::MacroDelimiter::Paren(Paren::default()),
tokens: quote! { (always) },
}),
};
fn_item.attrs.push(attr);

Expand Down
4 changes: 2 additions & 2 deletions impl/src/call_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use heck::SnakeCase;
use heck::ToSnakeCase as _;
use log::debug;
use proc_macro2::TokenStream;
use quote::quote;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub(crate) fn call_with_impl(
.items
.iter_mut()
.filter_map(|impl_item| match impl_item {
syn::ImplItem::Method(method) => match (
syn::ImplItem::Fn(method) => match (
&method.vis,
method.sig.asyncness,
method.sig.unsafety,
Expand Down
18 changes: 16 additions & 2 deletions impl/src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use quote::quote;
use syn::{Pat, PatIdent};

pub trait ForeignArgExt {
fn to_foreign_param(&self) -> Result<syn::PatType, syn::Error>;
Expand All @@ -23,16 +24,29 @@ impl ForeignArgExt for syn::PatType {

impl ForeignArgExt for syn::Receiver {
fn to_foreign_param(&self) -> Result<syn::PatType, syn::Error> {
let ident = syn::parse2(quote! { __handle }).unwrap();
Ok(syn::PatType {
attrs: vec![],
pat: syn::parse2(quote! { __handle }).unwrap(),
pat: Box::new(Pat::Ident(PatIdent {
attrs: vec![],
by_ref: None,
mutability: None,
ident,
subpat: None,
})),
colon_token: <syn::Token![:]>::default(),
ty: Box::new(syn::parse2(quote! { *const ::std::ffi::c_void }).unwrap()),
})
}

fn to_foreign_arg(&self) -> Result<syn::Pat, syn::Error> {
Ok(syn::parse2(quote! { __handle }).unwrap())
Ok(Pat::Ident(PatIdent {
attrs: vec![],
by_ref: None,
mutability: None,
ident: syn::parse2(quote! { __handle }).unwrap(),
subpat: None,
}))
}
}

Expand Down
10 changes: 7 additions & 3 deletions impl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
extern crate proc_macro;

use ctor::ctor;
use darling::FromMeta;
use darling::{ast::NestedMeta, Error, FromMeta};
use proc_macro2::TokenStream;
use quote::quote;
use syn::AttributeArgs;

mod attr;
mod call_fn;
Expand All @@ -22,7 +21,12 @@ pub fn marshal(
params: proc_macro::TokenStream,
function: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let params = syn::parse_macro_input!(params as AttributeArgs);
let params = match NestedMeta::parse_meta_list(params.into()) {
Ok(v) => v,
Err(e) => {
return TokenStream::from(Error::from(e).write_errors()).into();
}
};

let params = match InvokeParams::from_list(&params) {
Ok(v) => v,
Expand Down
4 changes: 2 additions & 2 deletions src/arc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::convert::Infallible;
use std::error::Error;
use std::marker::PhantomData;
use std::sync::Arc;
use std::mem::MaybeUninit;
use std::sync::Arc;

use crate::TraitObject;

Expand Down Expand Up @@ -31,7 +31,7 @@ impl<T: ?Sized> ReturnType for ArcMarshaler<T> {
TraitObject {
data: std::ptr::null_mut(),
vtable: std::ptr::null_mut(),
ty: PhantomData
ty: PhantomData,
}
}
}
Expand Down

0 comments on commit ee4a9f5

Please sign in to comment.