Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #56

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions compile_tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion compile_tests/tests/compile-fail/bad_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use savefile_derive::savefile_abi_export;
pub trait ExampleTrait {
fn get(&mut self, x: u32) -> u32;
}
#[derive(Default)]
struct ExampleImpl {

}
Expand All @@ -24,6 +25,7 @@ impl ExampleTrait for ExampleImpl {
}
// Test what happens when you mix up the ordering of trait and impl:
savefile_abi_export!(ExampleTrait, ExampleImpl);
//~^ 26:1: 26:48: expected trait, found struct `ExampleImpl` [E0404]
//~^ 27:22: 27:34: trait objects must include the `dyn` keyword [E0782]
//~^^ 27:36: 27:47: expected trait, found struct `ExampleImpl` [E0404]

fn main() {}
2 changes: 1 addition & 1 deletion compile_tests/tests/compile-fail/bad_export2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ struct ExampleImpl {

// Forgot to implement trait
savefile_abi_export!(ExampleImpl, ExampleTrait);
//~^ 23:1: 23:48: the trait bound `ExampleImpl: ExampleTrait` is not satisfied [E0277]
//~^ 23:22: 23:47: the trait bound `ExampleImpl: ExampleTrait` is not satisfied [E0277]

fn main() {}
12 changes: 3 additions & 9 deletions compile_tests/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extern crate compiletest_rs as compiletest;

use std::env;
use std::path::PathBuf;

fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) {
Expand All @@ -11,14 +10,9 @@ fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) {

let dir = custom_dir.unwrap_or(mode);
config.src_base = PathBuf::from(format!("tests/{}", dir));
config.target_rustcflags = Some("-L target/debug -L target/debug/deps".to_string());
config.llvm_filecheck = Some(
env::var("FILECHECK")
.unwrap_or("FileCheck".to_string())
.into(),
);
//config.clean_rmeta();
//config.clean_rlib();
config.target_rustcflags = Some("-L target/debug -L target/debug/deps --edition 2021".to_string());
config.llvm_filecheck = Some("FileCheck".to_string().into());

config.strict_headers = true;

compiletest::run_tests(&config);
Expand Down
5 changes: 5 additions & 0 deletions savefile-abi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.3](https://github.com/avl/savefile/compare/savefile-abi-v0.17.2...savefile-abi-v0.17.3) - 2024-05-09

### Other
- format

## [0.17.2](https://github.com/avl/savefile/compare/savefile-abi-v0.17.1...savefile-abi-v0.17.2) - 2024-05-05

### Other
Expand Down
6 changes: 3 additions & 3 deletions savefile-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "savefile-abi"
version = "0.17.2"
version = "0.17.3"
edition = "2021"
authors = ["Anders Musikka <[email protected]>"]
documentation = "https://docs.rs/savefile-abi/"
Expand All @@ -16,7 +16,7 @@ keywords = ["dylib", "dlopen", "ffi"]
license = "MIT/Apache-2.0"

[dependencies]
savefile = { path="../savefile", version = "=0.17.2" }
savefile-derive = { path="../savefile-derive", version = "=0.17.2" }
savefile = { path="../savefile", version = "=0.17.3" }
savefile-derive = { path="../savefile-derive", version = "=0.17.3" }
byteorder = "1.4"
libloading = "0.8"
14 changes: 8 additions & 6 deletions savefile-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ use savefile::{
diff_schema, load_file_noschema, load_noschema, save_file_noschema, AbiMethodInfo, AbiTraitDefinition, Deserialize,
Deserializer, LittleEndian, SavefileError, Schema, Serializer, CURRENT_SAVEFILE_LIB_VERSION,
};
use std::any::TypeId;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::hash::Hash;
Expand All @@ -314,7 +315,6 @@ use std::path::Path;
use std::ptr::null;
use std::sync::{Mutex, MutexGuard};
use std::{ptr, slice};
use std::any::TypeId;

use byteorder::ReadBytesExt;
use libloading::{Library, Symbol};
Expand Down Expand Up @@ -853,7 +853,7 @@ pub fn parse_return_value_impl<T>(
/// Parse an RawAbiCallResult instance into a `Result<Box<dyn T>, SavefileError>` .
/// This is used on the caller side, and the type T will always be statically known.
/// TODO: There's some duplicated code here, compare parse_return_value
pub fn parse_return_boxed_trait<T:'static>(outcome: &RawAbiCallResult) -> Result<Box<AbiConnection<T>>, SavefileError>
pub fn parse_return_boxed_trait<T: 'static>(outcome: &RawAbiCallResult) -> Result<Box<AbiConnection<T>>, SavefileError>
where
T: AbiExportable + ?Sized,
{
Expand All @@ -875,7 +875,7 @@ static ENTRY_CACHE: Mutex<
> = Mutex::new(None);

static ABI_CONNECTION_TEMPLATES: Mutex<
Option<HashMap<(TypeId,unsafe extern "C" fn(flag: AbiProtocol)), AbiConnectionTemplate>>,
Option<HashMap<(TypeId, unsafe extern "C" fn(flag: AbiProtocol)), AbiConnectionTemplate>>,
> = Mutex::new(None);

struct Guard<'a, K: Hash + Eq, V> {
Expand Down Expand Up @@ -972,8 +972,10 @@ pub unsafe extern "C" fn abi_result_receiver<T: Deserialize>(

/// Raw entry point for receiving return values from other shared libraries
#[doc(hidden)]
pub unsafe extern "C" fn abi_boxed_trait_receiver<T:'static>(outcome: *const RawAbiCallResult, result_receiver: *mut ())
where
pub unsafe extern "C" fn abi_boxed_trait_receiver<T: 'static>(
outcome: *const RawAbiCallResult,
result_receiver: *mut (),
) where
T: AbiExportable + ?Sized,
{
let outcome = unsafe { &*outcome };
Expand Down Expand Up @@ -1402,7 +1404,7 @@ impl<T: AbiExportable + ?Sized + 'static> AbiConnection<T> {
// In principle, it would be enough to key 'templates' based on 'remote_entry'.
// However, if we do, and the user ever uses AbiConnection<T> with the _wrong_ entry point,
// we risk poisoning the cache with erroneous data.
let template = match templates.entry((typeid,remote_entry)) {
let template = match templates.entry((typeid, remote_entry)) {
Entry::Occupied(template) => template.get().clone(),
Entry::Vacant(vacant) => {
let own_version = T::get_latest_version();
Expand Down
5 changes: 5 additions & 0 deletions savefile-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.3](https://github.com/avl/savefile/compare/savefile-derive-v0.17.2...savefile-derive-v0.17.3) - 2024-05-09

### Other
- Merge remote-tracking branch 'origin/master' into minor_v19

## [0.17.2](https://github.com/avl/savefile/compare/savefile-derive-v0.17.1...savefile-derive-v0.17.2) - 2024-05-05

### Other
Expand Down
5 changes: 4 additions & 1 deletion savefile-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "savefile-derive"
version = "0.17.2"
version = "0.17.3"
authors = ["Anders Musikka <[email protected]>"]
repository = "https://github.com/avl/savefile"

description = "Custom derive macros for savefile crate - simple, convenient, fast, versioned, binary serialization/deserialization library."

Expand All @@ -13,6 +14,8 @@ categories = ["encoding"]

license = "MIT/Apache-2.0"

edition = "2021"

[features]
default = []
nightly = []
Expand Down
4 changes: 2 additions & 2 deletions savefile-derive/src/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common::{check_is_remove, get_extra_where_clauses, parse_attr_tag, FieldInfo, RemovedType};
use get_enum_size;
use crate::common::{check_is_remove, get_extra_where_clauses, parse_attr_tag, FieldInfo, RemovedType};
use crate::get_enum_size;
use proc_macro2::{Literal, TokenStream};
use syn::spanned::Spanned;
use syn::DeriveInput;
Expand Down
45 changes: 31 additions & 14 deletions savefile-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ use common::{
check_is_remove, compile_time_check_reprc, compile_time_size, get_extra_where_clauses, parse_attr_tag,
path_to_string, FieldInfo,
};
use proc_macro2::Span;
use proc_macro2::{Span, TokenTree};
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::iter::IntoIterator;
use syn::__private::bool;
use syn::spanned::Spanned;
use syn::token::Paren;
use syn::token::{Paren};
use syn::Type::Tuple;
use syn::{
DeriveInput, FnArg, GenericParam, Generics, Ident, ImplGenerics, Index, ItemTrait, Pat, ReturnType, TraitItem,
Type, TypeGenerics, TypeParamBound, TypeTuple,
};
use syn::{DeriveInput, FnArg, GenericParam, Generics, Ident, ImplGenerics, Index, ItemTrait, Pat, ReturnType, TraitItem, Type, TypeGenerics, TypeParamBound, TypeTuple};
fn implement_fields_serialize(
field_infos: Vec<FieldInfo>,
implicit_self: bool,
Expand Down Expand Up @@ -564,21 +561,41 @@ pub fn savefile_abi_exportable(
}
#[proc_macro_error]
#[proc_macro]
pub fn savefile_abi_export(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = item.to_string();
let symbols: Vec<_> = input.split(',').map(|x| x.trim()).collect();
if symbols.len() != 2 {
abort!(input.span(), "savefile_abi_export requires two parameters. The first parameter is the implementing type, the second is the trait it implements.");
pub fn savefile_abi_export(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let tokens = proc_macro2::TokenStream::from(item);

let mut tokens_iter = tokens.into_iter();

let Some(implementing_type) = tokens_iter.next() else {
abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements.");
};
let Some(comma) = tokens_iter.next() else {
abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements.");
};
if let TokenTree::Punct(p) = comma {
if p.as_char() != ',' {
abort!(p.span(), "Expected a comma (','). The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements, and these must be separated by a comma.");
}
} else {
abort!(comma.span(), "Expected a comma (','). The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements, and these must be separated by a comma.");

}
let Some(trait_type) = tokens_iter.next() else {
abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements. Expected trait name.");
};

if let Some(extra) = tokens_iter.next() {
abort!(extra.span(), "Unexpected token. The macro savefile_abi_export! requires exactly two parameters. The first parameter must be the implementing type, the second is the trait it implements.");
}


let defspan = Span::call_site();
let uses = quote_spanned! { defspan =>
extern crate savefile_abi;
use savefile_abi::{AbiProtocol, AbiExportableImplementation, abi_entry,parse_return_value_impl};
};

let implementing_type = Ident::new(symbols[0], Span::call_site());
let trait_type = Ident::new(symbols[1], Span::call_site());
let abi_entry = Ident::new(("abi_entry_".to_string() + symbols[1]).as_str(), Span::call_site());
let abi_entry = Ident::new(("abi_entry_".to_string() + &trait_type.to_string()).as_str(), Span::call_site());

let expanded = quote! {
#[allow(clippy::double_comparisons)]
Expand Down
2 changes: 1 addition & 1 deletion savefile-derive/src/savefile_abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::{compile_time_check_reprc, compile_time_size};
use crate::common::{compile_time_check_reprc, compile_time_size};
use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::ToTokens;
use std::collections::HashMap;
Expand Down
6 changes: 3 additions & 3 deletions savefile-derive/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use proc_macro2::{Span, TokenStream};
use syn::DeriveInput;

use common::{get_extra_where_clauses, parse_attr_tag, FieldInfo};
use get_enum_size;
use implement_fields_serialize;
use crate::common::{get_extra_where_clauses, parse_attr_tag, FieldInfo};
use crate::get_enum_size;
use crate::implement_fields_serialize;
use syn::spanned::Spanned;

pub(super) fn savefile_derive_crate_serialize(input: DeriveInput) -> TokenStream {
Expand Down
7 changes: 1 addition & 6 deletions savefile-min-build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

use savefile_derive::Savefile;


#[derive(Debug, Savefile, PartialEq)]
pub enum TestStructEnum {
Variant2 { a: u8, b: u8 },
}

#[test]
fn test() {

}

fn test() {}
2 changes: 1 addition & 1 deletion savefile-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nightly=["savefile/nightly"]

[dependencies]
savefile = { path = "../savefile", features = ["size_sanity_checks", "encryption", "compression","bit-set","bit-vec","rustc-hash","serde_derive", "quickcheck"]}
savefile-derive = { path = "../savefile-derive", version = "=0.17.2" }
savefile-derive = { path = "../savefile-derive", version = "=0.17.3" }
savefile-abi = { path = "../savefile-abi" }
bit-vec = "0.6"
arrayvec="0.7"
Expand Down
2 changes: 1 addition & 1 deletion savefile-test/src/enum_variant_versioning.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use assert_roundtrip_version;
use savefile::{Removed, Packed};
use savefile::{Packed, Removed};
use {assert_roundtrip, assert_roundtrip_to_new_version};

#[repr(u8)]
Expand Down
Loading
Loading