chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
This commit is contained in:
@ -1,18 +1,18 @@
|
||||
/*!
|
||||
* Nyash Finalization System - Memory Management
|
||||
*
|
||||
*
|
||||
* fini()によるメモリ管理システムの実装
|
||||
* - 解放済みBoxの追跡
|
||||
* - スコープベースの自動解放
|
||||
* - 再代入時の自動解放
|
||||
*/
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::fmt;
|
||||
use crate::box_trait::NyashBox;
|
||||
use crate::instance_v2::InstanceBox;
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
lazy_static! {
|
||||
/// グローバルな解放済みBox ID管理
|
||||
@ -44,19 +44,19 @@ impl BoxFinalizer {
|
||||
excluded_boxes: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 新しいBoxを追跡対象に追加
|
||||
pub fn track(&mut self, nyash_box: Box<dyn NyashBox>) {
|
||||
let box_id = nyash_box.box_id();
|
||||
self.created_boxes.push((box_id, nyash_box));
|
||||
}
|
||||
|
||||
|
||||
/// 指定したBoxを解放対象から除外(関数の返り値など)
|
||||
pub fn exclude_from_finalization(&mut self, nyash_box: &Box<dyn NyashBox>) {
|
||||
let box_id = nyash_box.box_id();
|
||||
self.excluded_boxes.insert(box_id);
|
||||
}
|
||||
|
||||
|
||||
/// スコープ終了時に全てのBoxを解放(除外対象を除く)
|
||||
pub fn finalize_all(&mut self) {
|
||||
// 作成順(古い順)に解放
|
||||
@ -65,7 +65,7 @@ impl BoxFinalizer {
|
||||
if self.excluded_boxes.contains(box_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if !is_finalized(*box_id) {
|
||||
// fini()メソッドを呼び出す(存在する場合)
|
||||
if let Some(instance) = nyash_box.as_any().downcast_ref::<InstanceBox>() {
|
||||
@ -96,17 +96,17 @@ impl fmt::Debug for BoxFinalizer {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_finalization_tracking() {
|
||||
let box_id = 12345;
|
||||
assert!(!is_finalized(box_id));
|
||||
|
||||
|
||||
mark_as_finalized(box_id);
|
||||
assert!(is_finalized(box_id));
|
||||
|
||||
|
||||
// 二重解放チェック
|
||||
mark_as_finalized(box_id); // 問題なし
|
||||
assert!(is_finalized(box_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user