Skip to content

Commit

Permalink
1. Removing unnecessary "inline(always)" cases, replacing them with r…
Browse files Browse the repository at this point in the history
…egular "inline".

2. Renaming the build flag "always_build_flagstable" to "flags_table".
3. Renaming the build flag "allow_fullinternal_debug_assertions" to "allow_extended_debug_assertions".
4. Refactoring multiple names in the flags table.
5. Improving function naming.
6. Improving the code for cold triggers.
  • Loading branch information
denisandroid committed Jul 6, 2024
1 parent 3f5e456 commit 054aa37
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 145 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
- name: Run cargo alltest
run: cargo test --all-features --verbose
- name: PanicManDrop
run: cargo test --no-default-features --features always_build_flagstable,allow_fullinternal_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_panic,support_panic_trig --lib --verbose
run: cargo test --no-default-features --features flags_table,allow_extended_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_panic,support_panic_trig --lib --verbose
- name: AbortManDrop
run: cargo test --no-default-features --features always_build_flagstable,allow_fullinternal_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_abort,support_abort_trig --lib --verbose
run: cargo test --no-default-features --features flags_table,allow_extended_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_abort,support_abort_trig --lib --verbose
- name: HookFnManDrop
run: cargo test --no-default-features --features always_build_flagstable,allow_fullinternal_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_hookfn,support_hookfn_trig --lib --verbose
run: cargo test --no-default-features --features flags_table,allow_extended_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_hookfn,support_hookfn_trig --lib --verbose
- name: CountFnManDrop
run: cargo test --no-default-features --features always_build_flagstable,allow_fullinternal_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_count,support_count_trig --lib --verbose
run: cargo test --no-default-features --features flags_table,allow_extended_debug_assertions,always_check_in_case_debug_assertions,always_deftrig_count,support_count_trig --lib --verbose
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
license = "Apache-2.0"
readme = "README.md"

description = "A safe version of ManuallyDrop with various features and options to track undefined behavior when working with ManuallyDrop."
description = "ManuallyDrop Safe: A robust version of ManuallyDrop with features and options for tracking undefined behavior."
keywords = ["safe_manually_drop", "safemanuallydrop", "SafeManuallyDrop", "no_std", "clucompany"]
categories = ["development-tools", "development-tools::testing", "development-tools::debugging", "api-bindings", "memory-management"]

Expand Down Expand Up @@ -41,15 +41,15 @@ default = [
# and always_safe_manuallydrop options). This flag type only applies to internal
# library function checks, it is independent of ManuallyDrop and its valid or invalid usage.
#
# "allow_fullinternal_debug_assertions",
# "allow_extended_debug_assertions",

# Preserve unsafe fn flags even if functions are safe
# (may be required for additional compatibility with the standard API)
"always_compatible_stdapi",

# Always create a modular table of library flags used in the build.
# (crate::core::flags)
"always_build_flagstable",
"flags_table",

# Trigs:
#
Expand Down Expand Up @@ -109,11 +109,11 @@ always_safe_manuallydrop = []
# the debug_assertions flag is enabled (does not depend on the always_check_in_case_debug_assertions
# and always_safe_manuallydrop options). This flag type only applies to internal
# library function checks, it is independent of ManuallyDrop and its valid or invalid usage.
allow_fullinternal_debug_assertions = []
allow_extended_debug_assertions = []

# Always create a modular table of library flags used in the build.
# (crate::core::flags)
always_build_flagstable = []
flags_table = []

support_hookfn_trig = []
# Support for CounterManuallyDrop, in case of undefined behavior,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ features = [
// and always_safe_manuallydrop options). This flag type only applies to internal
// library function checks, it is independent of ManuallyDrop and its valid or invalid usage.
//
// "allow_fullinternal_debug_assertions",
// "allow_extended_debug_assertions",
// Preserve unsafe fn flags even if functions are safe
// (may be required for additional compatibility with the standard API)
"always_compatible_stdapi",
// Always create a modular table of library flags used in the build.
// (crate::core::flags)
"always_build_flagstable",
"flags_table",
// Trigs:
//
Expand Down
34 changes: 18 additions & 16 deletions src/core/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/// Whether a table of build flags to use was created
/// when the library was compiled.
pub const IS_BUILD_FLAGSTABLE: bool = true;
pub const BUILD_FLAG_TABLE_CREATED: bool = true;

/// Depending on the build flag, a protected version of ManuallyDrop or
/// an unprotected version of ManuallyDrop with a default trigger.
pub const IS_SAFE_MODE: bool = crate::ManuallyDrop::is_safe_mode();
pub const SAFE_MANUALLYDROP_ENABLED: bool = crate::ManuallyDrop::is_safe_mode();

/// Whether the library build flag was used to support panic_trig.
pub const IS_SUPPORT_PANIC_TRIG: bool = {
pub const BUILD_FLAG_PANIC_TRIGGER_ENABLED: bool = {
#[cfg(feature = "support_panic_trig")]
{
true
Expand All @@ -22,7 +22,7 @@ pub const IS_SUPPORT_PANIC_TRIG: bool = {
};

/// Whether the library build flag was used to support hookfn_trig.
pub const IS_SUPPORT_HOOKFN_TRIG: bool = {
pub const BUILD_FLAG_HOOKFN_TRIGGER_ENABLED: bool = {
#[cfg(feature = "support_hookfn_trig")]
{
true
Expand All @@ -35,7 +35,7 @@ pub const IS_SUPPORT_HOOKFN_TRIG: bool = {
};

/// Whether the library build flag was used to support abort_trig.
pub const IS_SUPPORT_ABORT_TRIG: bool = {
pub const BUILD_FLAG_ABORT_TRIGGER_ENABLED: bool = {
#[cfg(feature = "support_abort_trig")]
{
true
Expand All @@ -48,7 +48,7 @@ pub const IS_SUPPORT_ABORT_TRIG: bool = {
};

/// Whether the library build flag was used to support count_trig.
pub const IS_SUPPORT_COUNT_TRIG: bool = {
pub const BUILD_FLAG_COUNT_TRIGGER_ENABLED: bool = {
#[cfg(feature = "support_count_trig")]
{
true
Expand All @@ -61,10 +61,10 @@ pub const IS_SUPPORT_COUNT_TRIG: bool = {
};

/// Whether the library build flag was used to support loop_trig.
pub const IS_SUPPORT_LOOP_TRIG: bool = true;
pub const BUILD_FLAG_LOOP_TRIGGER_ENABLED: bool = true;

/// Ability to determine if an empty loop trigger has been executed.
pub const IS_SUPPORT_LOOP_IS_TRIG: bool = {
pub const BUILD_FLAG_LOOP_IS_TRIGGER_ENABLED: bool = {
#[cfg(feature = "support_istrig_loop")]
{
true
Expand All @@ -79,24 +79,26 @@ pub const IS_SUPPORT_LOOP_IS_TRIG: bool = {
/// Enable additional internal checks of the SafeManuallyDrop library when
/// the debug_assertions flag is enabled (does not depend on the always_check_in_case_debug_assertions
/// and always_safe_manuallydrop options).
pub const IS_FULLINTERNAL_DEBUG_ASSERTIONS: bool = {
#[cfg(feature = "allow_fullinternal_debug_assertions")]
pub const BUILD_FLAG_EXTENDED_DEBUG_ASSERTIONS_ENABLED: bool = {
#[cfg(feature = "allow_extended_debug_assertions")]
{
true
}

#[cfg(not(feature = "allow_fullinternal_debug_assertions"))]
#[cfg(not(feature = "allow_extended_debug_assertions"))]
{
false
}
};

/// Whether the default behavior autodetection was used for ManuallyDrop.
pub const IS_AUTO_DETECT_DEFTRIG: bool = crate::core::trig::IS_AUTO_DETECT_DEFTRIG;
pub const BUILD_FLAG_AUTO_DETECT_DEFTRIG_ENABLED: bool =
crate::core::trig::BUILD_FLAG_AUTO_DETECT_DEFTRIG_ENABLED;

/// If the build was done using "all functions" (cargo test/doc/build --all-features), the required behavior in a safe mandrop cannot be determined,
/// if this flag is active, EmptyLoopTrigManuallyDrop will be used.
pub const IS_INVALID_AUTO_DETECT_DEFTRIG: bool = crate::core::trig::IS_INVALID_AUTO_DETECT_DEFTRIG;
pub const BUILD_FLAG_INVALID_AUTO_DETECT_DEFTRIG_ENABLED: bool =
crate::core::trig::BUILD_FLAG_INVALID_AUTO_DETECT_DEFTRIG_ENABLED;

#[cfg(test)]
#[test]
Expand All @@ -106,7 +108,7 @@ fn test_flag_is_safe_mode() {

#[cfg(feature = "always_safe_manuallydrop")]
{
assert_eq!(IS_SAFE_MODE, true);
assert_eq!(SAFE_MANUALLYDROP_ENABLED, true);

//#[allow(unused_assignments)] // error[E0658]: attributes on expressions are experimental
is_checked_c = 1;
Expand All @@ -117,7 +119,7 @@ fn test_flag_is_safe_mode() {
{
// clippy::assertions_on_constants why? it's part of this test, it's okay.
#![allow(clippy::assertions_on_constants)]
assert!(IS_SAFE_MODE);
assert!(SAFE_MANUALLYDROP_ENABLED);

is_checked_c = 1;
}
Expand All @@ -127,7 +129,7 @@ fn test_flag_is_safe_mode() {
feature = "always_safe_manuallydrop"
)))]
{
assert_eq!(IS_SAFE_MODE, false);
assert_eq!(SAFE_MANUALLYDROP_ENABLED, false);

is_checked_c = is_checked_c + 1;
}
Expand Down
Loading

0 comments on commit 054aa37

Please sign in to comment.