From c319c0b604722e4ee0d24655576ebd6505a49dc0 Mon Sep 17 00:00:00 2001 From: ChUrl Date: Tue, 19 Jul 2022 14:51:55 +0200 Subject: [PATCH] remove smarptrdemo impl until i have my own one --- c_os/user/MainMenu.cc | 7 +- c_os/user/demo/SmartPointerDemo.cc | 106 ----------------------------- 2 files changed, 3 insertions(+), 110 deletions(-) delete mode 100644 c_os/user/demo/SmartPointerDemo.cc diff --git a/c_os/user/MainMenu.cc b/c_os/user/MainMenu.cc index 540501d..48ed29d 100644 --- a/c_os/user/MainMenu.cc +++ b/c_os/user/MainMenu.cc @@ -7,7 +7,6 @@ #include "user/demo/LinkedListDemo.h" #include "user/demo/PCSPKdemo.h" #include "user/demo/PreemptiveThreadDemo.h" -#include "user/demo/SmartPointerDemo.h" #include "user/demo/TextDemo.h" #include "user/demo/VBEdemo.h" @@ -69,9 +68,9 @@ void MainMenu::run() { case 'e': choosen_demo = new ArrayDemo(); break; - case 'r': - choosen_demo = new SmartPointerDemo(); - break; + // case 'r': + // choosen_demo = new SmartPointerDemo(); + // break; } if (choosen_demo != NULL) { diff --git a/c_os/user/demo/SmartPointerDemo.cc b/c_os/user/demo/SmartPointerDemo.cc deleted file mode 100644 index 3bf7e1c..0000000 --- a/c_os/user/demo/SmartPointerDemo.cc +++ /dev/null @@ -1,106 +0,0 @@ -#include "user/demo/SmartPointerDemo.h" -#include "kernel/threads/IdleThread.h" -#include "user/demo/ArrayDemo.h" -#include "user/demo/ArrayListDemo.h" -#include "user/demo/BlueScreenDemo.h" -#include "user/demo/HeapDemo.h" -#include "user/demo/KeyboardDemo.h" -#include "user/demo/LinkedListDemo.h" -#include "user/demo/PCSPKdemo.h" -#include "user/demo/PreemptiveThreadDemo.h" -#include "user/demo/TextDemo.h" -#include "user/demo/VBEdemo.h" -#include - -// NOTE: I had weird linker errors (bc of smart pointers) I couldn't figure out, -// so I tried to determine what caused them -// NOTE: Found the problem: Because we compile with -nostdlib the reference counting code of the -// shared_ptr is not available. Can only use unique_ptr -// NOTE: Because using unique_ptr inside C-Style array is difficult (deletion) I can't use them - -void SmartPointerDemo::run() { - // Log from threaad to see status between alloc logs - - log << INFO << "Initializing unique_ptr:" << endl; - { - std::unique_ptr int1 = std::make_unique(1); - log << INFO << *int1 << endl; - } - log << INFO << "Should be uninitialized by now..." << endl; - - // ================================================================== - - log << INFO << "Testing unique_ptr..." << endl; - { - std::unique_ptr thread1 = std::make_unique(); - std::unique_ptr thread2 = std::make_unique(); - std::unique_ptr thread3 = std::make_unique(&PCSPK::aerodynamic); - std::unique_ptr thread4 = std::make_unique(); - std::unique_ptr thread5 = std::make_unique(); - std::unique_ptr thread6 = std::make_unique(); - std::unique_ptr thread7 = std::make_unique(); - std::unique_ptr thread8 = std::make_unique(3); - std::unique_ptr thread9 = std::make_unique(); - std::unique_ptr thread10 = std::make_unique(); - std::unique_ptr thread11 = std::make_unique(); - } - log << INFO << "Finished." << endl; - - // log << INFO << "Testing shared_ptr..." << endl; - // { - // std::shared_ptr thread1 = std::make_shared(); - // std::shared_ptr thread2 = std::make_shared(); - // std::shared_ptr thread3 = std::make_shared(&PCSPK::aerodynamic); - // std::shared_ptr thread4 = std::make_shared(); - // std::shared_ptr thread5 = std::make_shared(); - // std::shared_ptr thread6 = std::make_shared(); - // std::shared_ptr thread7 = std::make_shared(); - // std::shared_ptr thread8 = std::make_shared(3); - // std::shared_ptr thread9 = std::make_shared(); - // std::shared_ptr thread10 = std::make_shared(); - // std::shared_ptr thread11 = std::make_shared(); - // } - // log << INFO << "Finished." << endl; - - // ================================================================== - - log << INFO << "Initializing unique_ptr:" << endl; - { - std::unique_ptr int1 = std::make_unique(1); - std::unique_ptr int2; - - log << INFO << "Moving:" << endl; - int2 = std::move(int1); - log << INFO << *int2 << endl; - } - log << INFO << "Should be unitialized by now..." << endl; - - // ================================================================== - - log << INFO << "Testing Lists..." << endl; - { - // Doesn't work - // std::unique_ptr[]> buf = std::make_unique[]>(10); - - // Something like this happens in the ArrayList - std::unique_ptr* buf = new std::unique_ptr[10]; - std::unique_ptr* new_buf = new std::unique_ptr[10]; - - log << INFO << "Allocating Thread in buf..." << endl; - buf[0] = std::make_unique(); - - log << INFO << "Moving Thread to new_buf..." << endl; - new_buf[0] = std::move(buf[0]); - - // BUG: Because buf[0] is basically the same as buf there are double deletes happening. - // Can't be sure if the block wasn't reallocated and this deletes live data... - log << INFO << "Deleting buf..." << endl; - delete buf; - - log << INFO << "Deleting new_buf..." << endl; - delete new_buf; - } - log << INFO << "Finished." << endl; - - scheduler.exit(); -}