From cd7267d3c37fd65ef2ec2bbcb100bf7dfab5ee69 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 23 Mar 2023 01:48:49 +0200 Subject: [PATCH] Rename smart pointers --- Core/Driver/Driver.cpp | 2 +- Execute/Elf/BaseLoad.cpp | 2 +- Execute/Elf/Exec.cpp | 2 +- Execute/Elf/Parse.cpp | 2 +- Execute/Parse.cpp | 2 +- Execute/Spawn.cpp | 2 +- FileSystem/Filesystem.cpp | 40 +++++++++++++++++++-------------------- Kernel.cpp | 6 +++--- Recovery/RecoveryMain.cpp | 2 +- include/filesystem.hpp | 18 +++++++++--------- include/smartptr.hpp | 40 +++++++++++++++++++-------------------- 11 files changed, 59 insertions(+), 59 deletions(-) diff --git a/Core/Driver/Driver.cpp b/Core/Driver/Driver.cpp index f7cb66c..44908b8 100644 --- a/Core/Driver/Driver.cpp +++ b/Core/Driver/Driver.cpp @@ -174,7 +174,7 @@ namespace Driver Driver::Driver() { SmartCriticalSection(DriverInitLock); - shared_ptr DriverDirectory = vfs->Open(Config.DriverDirectory); + SharedPointer DriverDirectory = vfs->Open(Config.DriverDirectory); if (DriverDirectory->Status == VirtualFileSystem::FileStatus::OK) { foreach (auto driver in DriverDirectory->node->Children) diff --git a/Execute/Elf/BaseLoad.cpp b/Execute/Elf/BaseLoad.cpp index 6f264c6..a3f3fba 100644 --- a/Execute/Elf/BaseLoad.cpp +++ b/Execute/Elf/BaseLoad.cpp @@ -111,7 +111,7 @@ namespace Execute cwk_path_get_basename(Path, &BaseName, nullptr); TaskArchitecture Arch = TaskArchitecture::UnknownArchitecture; - shared_ptr ExFile = vfs->Open(Path); + SharedPointer ExFile = vfs->Open(Path); if (ExFile->Status != FileStatus::OK) { diff --git a/Execute/Elf/Exec.cpp b/Execute/Elf/Exec.cpp index 834dfb2..c3ab83c 100644 --- a/Execute/Elf/Exec.cpp +++ b/Execute/Elf/Exec.cpp @@ -154,7 +154,7 @@ namespace Execute memcpy((void *)InterpreterPath, (uint8_t *)ElfFile + ItrPhdr.p_offset, 256); debug("Interpreter: %s", InterpreterPath); - shared_ptr InterpreterFile = vfs->Open(InterpreterPath); + SharedPointer InterpreterFile = vfs->Open(InterpreterPath); if (InterpreterFile->Status != VirtualFileSystem::FileStatus::OK) warn("Failed to open interpreter file: %s", InterpreterPath); diff --git a/Execute/Elf/Parse.cpp b/Execute/Elf/Parse.cpp index a7dca44..18ff83d 100644 --- a/Execute/Elf/Parse.cpp +++ b/Execute/Elf/Parse.cpp @@ -207,7 +207,7 @@ namespace Execute } /* No need to check if it's valid, the GetBinaryType() call above does that. */ - shared_ptr File = vfs->Open(Interpreter); + SharedPointer File = vfs->Open(Interpreter); Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)File->node->Address; diff --git a/Execute/Parse.cpp b/Execute/Parse.cpp index 726a940..d675109 100644 --- a/Execute/Parse.cpp +++ b/Execute/Parse.cpp @@ -69,7 +69,7 @@ namespace Execute BinaryType GetBinaryType(char *Path) { BinaryType Type = BinaryType::BinTypeInvalid; - shared_ptr ExFile = vfs->Open(Path); + SharedPointer ExFile = vfs->Open(Path); if (ExFile->Status == VirtualFileSystem::FileStatus::OK) { diff --git a/Execute/Spawn.cpp b/Execute/Spawn.cpp index 24c7682..82f8385 100644 --- a/Execute/Spawn.cpp +++ b/Execute/Spawn.cpp @@ -20,7 +20,7 @@ namespace Execute .Process = nullptr, .Thread = nullptr}; - shared_ptr ExFile = vfs->Open(Path); + SharedPointer ExFile = vfs->Open(Path); if (ExFile->Status == VirtualFileSystem::FileStatus::OK) { diff --git a/FileSystem/Filesystem.cpp b/FileSystem/Filesystem.cpp index ec8e026..3c2af94 100644 --- a/FileSystem/Filesystem.cpp +++ b/FileSystem/Filesystem.cpp @@ -22,7 +22,7 @@ NewLock(VFSLock); namespace VirtualFileSystem { - shared_ptr Virtual::GetPathFromNode(Node *node) + SharedPointer Virtual::GetPathFromNode(Node *node) { vfsdbg("GetPathFromNode( Node: \"%s\" )", node->Name); Node *Parent = node; @@ -73,7 +73,7 @@ namespace VirtualFileSystem } // Allocate a new string for the final path - shared_ptr FinalPath; + SharedPointer FinalPath; FinalPath.reset(new char[Size]); size_t Offset = 0; @@ -152,9 +152,9 @@ namespace VirtualFileSystem return nullptr; } - shared_ptr Virtual::ConvertNodeToFILE(Node *node) + SharedPointer Virtual::ConvertNodeToFILE(Node *node) { - shared_ptr file = make_shared(); + SharedPointer file = MakeShared(); file->Status = FileStatus::OK; file->node = node; return file; @@ -256,17 +256,17 @@ namespace VirtualFileSystem return FileStatus::NotFound; } - shared_ptr Virtual::NormalizePath(const char *Path, Node *Parent) + SharedPointer Virtual::NormalizePath(const char *Path, Node *Parent) { vfsdbg("NormalizePath( Path: \"%s\" Parent: \"%s\" )", Path, Parent->Name); char *NormalizedPath = new char[strlen((char *)Path) + 1]; - shared_ptr RelativePath; + SharedPointer RelativePath; cwk_path_normalize(Path, NormalizedPath, strlen((char *)Path) + 1); if (cwk_path_is_relative(NormalizedPath)) { - shared_ptr ParentPath = GetPathFromNode(Parent); + SharedPointer ParentPath = GetPathFromNode(Parent); size_t PathSize = cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, nullptr, 0); RelativePath.reset(new char[PathSize + 1]); cwk_path_get_absolute(ParentPath.Get(), NormalizedPath, RelativePath.Get(), PathSize + 1); @@ -329,7 +329,7 @@ namespace VirtualFileSystem Node *CurrentParent = this->GetParent(Path, Parent); vfsdbg("Virtual::Create( Path: \"%s\" Parent: \"%s\" )", Path, Parent ? Parent->Name : CurrentParent->Name); - shared_ptr CleanPath = this->NormalizePath(Path, CurrentParent); + SharedPointer CleanPath = this->NormalizePath(Path, CurrentParent); vfsdbg("CleanPath: \"%s\"", CleanPath.Get()); if (PathExists(CleanPath.Get(), CurrentParent)) @@ -392,7 +392,7 @@ namespace VirtualFileSystem if (Parent == nullptr) Parent = FileSystemRoot; - shared_ptr CleanPath = this->NormalizePath(Path, Parent); + SharedPointer CleanPath = this->NormalizePath(Path, Parent); vfsdbg("CleanPath: \"%s\"", CleanPath.Get()); if (!PathExists(CleanPath.Get(), Parent)) @@ -440,10 +440,10 @@ namespace VirtualFileSystem FileStatus Virtual::Delete(Node *Path, bool Recursive, Node *Parent) { return Delete(GetPathFromNode(Path).Get(), Recursive, Parent); } /* TODO: REWORK */ - shared_ptr Virtual::Mount(const char *Path, FileSystemOperations *Operator) + SharedPointer Virtual::Mount(const char *Path, FileSystemOperations *Operator) { SmartLock(VFSLock); - shared_ptr file = make_shared(); + SharedPointer file = MakeShared(); if (unlikely(!Operator)) { @@ -467,7 +467,7 @@ namespace VirtualFileSystem return file; } - FileStatus Virtual::Unmount(shared_ptr File) + FileStatus Virtual::Unmount(SharedPointer File) { SmartLock(VFSLock); if (unlikely(File.Get())) @@ -476,7 +476,7 @@ namespace VirtualFileSystem return FileStatus::OK; } - size_t Virtual::Read(shared_ptr File, size_t Offset, uint8_t *Buffer, size_t Size) + size_t Virtual::Read(SharedPointer File, size_t Offset, uint8_t *Buffer, size_t Size) { SmartLock(VFSLock); if (unlikely(!File.Get())) @@ -500,7 +500,7 @@ namespace VirtualFileSystem return File->node->Operator->Read(File->node, Offset, Size, Buffer); } - size_t Virtual::Write(shared_ptr File, size_t Offset, uint8_t *Buffer, size_t Size) + size_t Virtual::Write(SharedPointer File, size_t Offset, uint8_t *Buffer, size_t Size) { SmartLock(VFSLock); if (unlikely(!File.Get())) @@ -525,7 +525,7 @@ namespace VirtualFileSystem } /* TODO: CHECK Open */ - shared_ptr Virtual::Open(const char *Path, Node *Parent) + SharedPointer Virtual::Open(const char *Path, Node *Parent) { SmartLock(VFSLock); vfsdbg("Opening %s with parent %s", Path, Parent ? Parent->Name : "(null)"); @@ -533,7 +533,7 @@ namespace VirtualFileSystem if (strcmp(Path, ".") == 0) { - shared_ptr file = make_shared(); + SharedPointer file = MakeShared(); file->node = Parent; if (unlikely(!file->node)) file->Status = FileStatus::NotFound; @@ -544,7 +544,7 @@ namespace VirtualFileSystem if (strcmp(Path, "..") == 0) { - shared_ptr file = make_shared(); + SharedPointer file = MakeShared(); if (Parent->Parent != nullptr) file->node = Parent->Parent; @@ -557,9 +557,9 @@ namespace VirtualFileSystem } Node *CurrentParent = this->GetParent(Path, Parent); - shared_ptr CleanPath = NormalizePath(Path, CurrentParent); + SharedPointer CleanPath = NormalizePath(Path, CurrentParent); - shared_ptr file = make_shared(); + SharedPointer file = MakeShared(); /* TODO: Check for other errors */ if (!PathExists(CleanPath.Get(), CurrentParent)) @@ -601,7 +601,7 @@ namespace VirtualFileSystem return file; } - FileStatus Virtual::Close(shared_ptr File) + FileStatus Virtual::Close(SharedPointer File) { SmartLock(VFSLock); if (unlikely(!File.Get())) diff --git a/Kernel.cpp b/Kernel.cpp index f72279c..8b40945 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -314,7 +314,7 @@ EXTERNC NIF void Main(BootInfo *Info) DevFS = vfs->Create("/system/dev", NodeFlags::DIRECTORY); else { - shared_ptr dev = vfs->Open("/system/dev"); + SharedPointer dev = vfs->Open("/system/dev"); if (dev->node->Flags != NodeFlags::DIRECTORY) { KPrint("\eE85230/system/dev is not a directory! Halting..."); @@ -328,7 +328,7 @@ EXTERNC NIF void Main(BootInfo *Info) MntFS = vfs->Create("/system/mnt", NodeFlags::DIRECTORY); else { - shared_ptr mnt = vfs->Open("/system/mnt"); + SharedPointer mnt = vfs->Open("/system/mnt"); if (mnt->node->Flags != NodeFlags::DIRECTORY) { KPrint("\eE85230/system/mnt is not a directory! Halting..."); @@ -342,7 +342,7 @@ EXTERNC NIF void Main(BootInfo *Info) ProcFS = vfs->Create("/system/proc", NodeFlags::DIRECTORY); else { - shared_ptr proc = vfs->Open("/system/proc", nullptr); + SharedPointer proc = vfs->Open("/system/proc", nullptr); if (proc->node->Flags != NodeFlags::DIRECTORY) { KPrint("\eE85230/system/proc is not a directory! Halting..."); diff --git a/Recovery/RecoveryMain.cpp b/Recovery/RecoveryMain.cpp index 95938d7..36ac05c 100644 --- a/Recovery/RecoveryMain.cpp +++ b/Recovery/RecoveryMain.cpp @@ -52,7 +52,7 @@ namespace Recovery return; } - shared_ptr pcm = vfs->Open(AudioFile); + SharedPointer pcm = vfs->Open(AudioFile); if (pcm->Status != FileStatus::OK) { diff --git a/include/filesystem.hpp b/include/filesystem.hpp index d325f98..7ce21c2 100644 --- a/include/filesystem.hpp +++ b/include/filesystem.hpp @@ -121,9 +121,9 @@ namespace VirtualFileSystem Node *FileSystemRoot = nullptr; public: - shared_ptr GetPathFromNode(Node *node); + SharedPointer GetPathFromNode(Node *node); Node *GetNodeFromPath(const char *Path, Node *Parent = nullptr); - shared_ptr ConvertNodeToFILE(Node *node); + SharedPointer ConvertNodeToFILE(Node *node); Node *GetParent(const char *Path, Node *Parent); Node *GetRootNode() { return FileSystemRoot; } @@ -132,7 +132,7 @@ namespace VirtualFileSystem Node *GetChild(const char *Name, Node *Parent); FileStatus RemoveChild(const char *Name, Node *Parent); - shared_ptr NormalizePath(const char *Path, Node *Parent = nullptr); + SharedPointer NormalizePath(const char *Path, Node *Parent = nullptr); bool PathExists(const char *Path, Node *Parent = nullptr); Node *CreateRoot(const char *RootName, FileSystemOperations *Operator); Node *Create(const char *Path, NodeFlags Flag, Node *Parent = nullptr); @@ -140,14 +140,14 @@ namespace VirtualFileSystem FileStatus Delete(const char *Path, bool Recursive = false, Node *Parent = nullptr); FileStatus Delete(Node *Path, bool Recursive = false, Node *Parent = nullptr); - shared_ptr Mount(const char *Path, FileSystemOperations *Operator); - FileStatus Unmount(shared_ptr File); + SharedPointer Mount(const char *Path, FileSystemOperations *Operator); + FileStatus Unmount(SharedPointer File); - size_t Read(shared_ptr File, size_t Offset, uint8_t *Buffer, size_t Size); - size_t Write(shared_ptr File, size_t Offset, uint8_t *Buffer, size_t Size); + size_t Read(SharedPointer File, size_t Offset, uint8_t *Buffer, size_t Size); + size_t Write(SharedPointer File, size_t Offset, uint8_t *Buffer, size_t Size); - shared_ptr Open(const char *Path, Node *Parent = nullptr); - FileStatus Close(shared_ptr File); + SharedPointer Open(const char *Path, Node *Parent = nullptr); + FileStatus Close(SharedPointer File); Virtual(); ~Virtual(); diff --git a/include/smartptr.hpp b/include/smartptr.hpp index 6416407..797d1bb 100644 --- a/include/smartptr.hpp +++ b/include/smartptr.hpp @@ -22,23 +22,23 @@ * the object is removed, the object is deleted. * * Basic Usage: - * smart_ptr pointer(new char()); + * SmartPointer pointer(new char()); * *pointer = 'a'; * printf("%c", *pointer); // Prints "a" */ template -class smart_ptr +class SmartPointer { T *m_RealPointer; public: - explicit smart_ptr(T *Pointer = nullptr) + explicit SmartPointer(T *Pointer = nullptr) { spdbg("Smart pointer created (%#lx)", m_RealPointer); m_RealPointer = Pointer; } - ~smart_ptr() + ~SmartPointer() { spdbg("Smart pointer deleted (%#lx)", m_RealPointer); delete m_RealPointer, m_RealPointer = nullptr; @@ -58,22 +58,22 @@ public: }; template -class auto_ptr +class AutoPointer { }; template -class unique_ptr +class UniquePointer { }; template -class weak_ptr +class WeakPointer { }; template -class shared_ptr +class SharedPointer { private: class Counter @@ -127,7 +127,7 @@ private: T *m_RealPointer; public: - explicit shared_ptr(T *Pointer = nullptr) + explicit SharedPointer(T *Pointer = nullptr) { m_RealPointer = Pointer; m_ReferenceCounter = new Counter(); @@ -136,7 +136,7 @@ public: (*m_ReferenceCounter)++; } - shared_ptr(shared_ptr &SPtr) + SharedPointer(SharedPointer &SPtr) { spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.m_RealPointer, SPtr.m_ReferenceCounter); m_RealPointer = SPtr.m_RealPointer; @@ -144,7 +144,7 @@ public: (*m_ReferenceCounter)++; } - ~shared_ptr() + ~SharedPointer() { spdbg("[%#lx] Shared pointer destructor called", this); (*m_ReferenceCounter)--; @@ -211,7 +211,7 @@ public: } } - void swap(shared_ptr &Other) + void swap(SharedPointer &Other) { spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)", this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter); @@ -225,42 +225,42 @@ public: }; template -struct remove_reference +struct RemoveReference { typedef T type; }; template -struct remove_reference +struct RemoveReference { typedef T type; }; template -struct remove_reference +struct RemoveReference { typedef T type; }; template -using remove_reference_t = typename remove_reference::type; +using RemoveReference_t = typename RemoveReference::type; template -T &&forward(remove_reference_t &t) +T &&forward(RemoveReference_t &t) { return static_cast(t); }; template -T &&forward(remove_reference_t &&t) +T &&forward(RemoveReference_t &&t) { return static_cast(t); }; template -shared_ptr make_shared(Args &&...args) +SharedPointer MakeShared(Args &&...args) { - return shared_ptr(new T(forward(args)...)); + return SharedPointer(new T(forward(args)...)); }; #endif // !__FENNIX_KERNEL_SMART_POINTER_H__